Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
ohshit-docker or a quick help with docker
As a little bit of an introduction, it is helpful to sometimes think of docker as running containers in seperate "lightweight" VMs. This is not really the case (https://geekflare.com/docker-vs-virtual-machine/) but it is a helpful abstraction for this brief intro.
Just to be sure where we are at lets try running a couple of commands to be sure we are in a good state.
It is an easy thing to do after a while to have a large amount of wasted space due to old and intermedate images sitting arround but not being used. An easy quick way to clean that up is with the "docker system prune". As the warning will tell you,
This will remove:
- all stopped containers
- all networks not used by at least one container
- all dangling images
- all dangling build cache
-a added to the command will also prune any stopped and or unused images as well.
A good way to cut down on the need to do this is to include the --rm comand to your docker run commands.
In your case of wanting to set up a zoneminder server another feature of docker is important to remember. Docker containers by default are ephemeral, that is when they exit anything that was inside the container is gone. In your case, any configurations and data will have evaporated each time you restart your computer etc. This is less than desireable.
You said that you ran the command
docker run zoneminderhq/zoneminder:latest-ubuntu18.04
Lets break down what this exactly means... you are asking the docker daemon to run the image created by zoneminderhq named zoneminder with the tab "latest-ubuntu18.04". If we go to the docker hub we can figure out what is actually in this image. https://hub.docker.com/r/zoneminderhq/zoneminder/dockerfile and clicking on the dockerfile tab will show you what is in your container when it was built, command by command.
The issue with your set of commands as I was saying before is that you didn't connect any ports to your local computer from the container and you didn't mount in any folders to use as long term storage between container runs.
You more likely want to run something like is shown on the docker page:
docker run --rm -d -t -p 1080:80 \
-e TZ='Europe/London' \
-v ~/zoneminder/events:/var/cache/zoneminder/events \
-v ~/zoneminder/images:/var/cache/zoneminder/images \
-v ~/zoneminder/mysql:/var/lib/mysql \
-v ~/zoneminder/logs:/var/log/zm \
--shm-size="512m" \
--name zoneminder \
zoneminderhq/zoneminder:latest-ubuntu18.04
Likely the first time you run you will need to also run before hand a script to create all the files...
mkdir ~zoneminder/
mkdir ~zoneminder/events
mkdir ~zoneminder/images
mkdir ~zoneminder/mysql
mkdir ~zoneminder/logs
So lets break down what the command is doing:
--rm cleanup any images after you exit from the container (I added this part)
-e is an environmental variable to pass into the container
-d run as detached ("daemon/service mode")
-t allocate a psudo-tty (don't worry about it right now)
-p expose port 80 on the container to your local port 1080
-v mount local folder to container folder
--shm sets the size of /dev/shm "tempfs"
--name an optional name (makes it easy to kill it when you want)
then the container name
By default if you don't tell it otherwise you will start the ENTRYPOINT in the dockerfile, but if you had wanted to you could replace the -d with a -i and add to the end of the file bash and you would have a bash shell running inside the container.
You should now be able to go to http://localhost:8080/zm and see the zoneminder server.
Finally you decide that it is time to kill the container and walk away, just run the command
docker kill zoneminder
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.