They used a whale as their icon, what other headline was I supposed to use?
So call me Aronnax and let’s search for that mysterious whale everyone is talking about.
Please do not expect this to be a review of docker or anything like that, my intention for these pages is to serve as a personal documentation of what I learned about docker, so I can come back to it later if needed and to provide some help to others in case they need it.
What is docker?
Docker is a technology to pack applications into containers in order to run them isolated from their host computer, think virtual machine, but a little less overhead. Instead of running an entire operating system, with all its resources, containers utilize the hosts resources, but keep the deployed software separated, more or less.
Why would I do that?
First up, containers help you to deploy software to any computer using exactly the same software stack as it was developed for. This is done through so called images. That already releases you of a lot of headaches.
Second, since the host does not need to virtualize a whole operating system in order to achieve one thing it uses way less resourced to accomplish the same task.
Third, it would seem that containers scale very well, but I haven’t gotten that far with my studies yet. Maybe I will update this later.
Sounds great, so what do I need to know?
First up docker needs to be installed on the desired host, not going to put anything about this here, since there are plenty of tutorials out there.
Second there are some very important terms one needs to know
The image, just like a disk image in a VM, is basically the packaged, run ready solution. It is a read-only filesystem that is used to deploy software, software stack and needed resources
When the image is loaded it becomes a container, the containers file system is writeable, although it is not a good idea to store data on it.
Volumes are basically directories on the host file system that are mounted to the containers file system. That way, any data stored is saved after a container is removed or replaced (e.g. during an update). Think /var/lib/mysql for example. You would not want that folder to disappear after an update.
A file used to create an image, it contains, for the lack of a better word, compiler directives.
FROM -> the base image you want to work form (OS, pre-built webserver…)
ENV -> Environment variables, e.g. TZ= to set the containers timezone
USER -> change to a specific user to run a command within the container on startup
CMD -> Run a command. Passed as an array [“command”,”paramter”]
COPY -> your files to add to the container
The file is always named Dockerfile, to build the image cd into your project directory and run “docker build -t [image name]
Also some important commands
docker ps -> List currently running containers, add -a to see all running and past containers
docker images -> list locally installed images
docker run -> start a container using an image
docker image pull -> manually download an image
docker start -> run a previously created container
docker stop -> stop running container
docker exec -> run command within a container
docker logs -> show logging information of a container
docker rm -> remove container
docker run -v -> mount volume to container syntax -v [hostdir]:[containerdir]
docker run -p -> Port-forwarding syntax -p [host prot]:[container port]
docker network create -> create a network so containers are able to communicate among each other (–network [network name] for docker run)
Docker Hub is a central page for plenty of pre-built images on can use to create containers head to hub.docker.com, sign up and you can start searching for images.
After spending a couple of evenings with this technology I am starting to like it, pre-built images like apache + php7 save a lot of time when deploying software, the docker command syntax is easy to learn and so far, in keeping with the book I bought to learn all this, I deployed many containers on my test-vm.
But I am far from really understanding it. With the help of a mastodon friend of mine (@email@example.com, he is pretty cool, follow him) who provided me with a couple of well documented docker compose files I managed to get firefly-iii (firefly-iii.org) and NextCloud (nextcloud.com) working within containers. My understanding of these compose files is rather basic by now, so I will write about them later. Also looking forward to experimenting with services, stacks, clusters and swarms or kubernetes which ever I will try out to run and deploy containers across multiple hosts.
All in all it is a very interesting technology and in the back of my head I am already thinking about options to run this at the company…