Let me be perfectly honest, there will probably not be a part 2. Easy as docker is, there’s still a bit of a barrier to entry. I’m a software dev, I don’t really want to configure vms, but, well, devops. I don’t need to know how to do everything, but I want some understanding of how these pieces fit together. So I took one of our projects and spent some time yesterday to containerized it. I’m going to go through how I went about it.
Step 1. The Search for Tutorials
I spent a while looking through tutorials. Trying to find a good one. Spoiler: I didn’t. I was able to make use of this one mostly: https://www.digitalocean.com/community/tutorials/docker-explained-how-to-containerize-python-web-applications It’s a very long tutorial that I was able to pick and choose some things out of. I’m really sad there isn’t a better tutorial. (That 5 minute docker tutorial is cute, but ultimately worthless.)
Step 2. Installing Docker on a Mac
I wanted to create docker containers on my laptop. It didn’t take long to discover this isn’t really something you can do directly. I wanted to avoid creating a vagrant-virtualbox just to create docker images, so I searched for the standard of what people do. The answer is they use something called boot2docker (https://github.com/boot2docker/osx-installer/releases/tag/v1.4.1), which, as it turns out, just just a linux virtualbox to run docker on. Go figure.
Step 3. Creating a Container — Dockerfile
Upon reading how to create a container manually, it seemed silly to not just create a Dockerfile. A Dockerfile is just a config file that allows docker to create the image. Having mild familiarity with vagrant configs and puppet, the Dockerfile is a way to keep a simple, replicable record of the docker image being created. And simple it is. The format is more readable than it’s cousin, Vagrantfile. It was a simple thing to create the Dockerfile for my Django app. (https://gist.github.com/jazahn/aca49f3e3f9a5b819bce) It uses only a few simple keywords. The most useful being RUN.
Step 4. Creating the Image — build
This was just a simple docker build command
docker build -t docker_image_label .
This creates a new image, labelled with the -t param.
Step 4.5. Finding and Removing Images
This will list all images (on the boot2docker vm) which you can choose to
docker rm <name>
Step 5. Running the Image — run
This was just a simple docker run command. There are several ways to run, I went with the following:
docker run -d -p 8080:8080 --name docker_instance_name docker_image_label
This just uses -d to run it as a daemon, -p to forward the ports* *It must be noted that “forwarding the ports” is only relevant to the boot2docker virtualbox. To see the result, you should make use of the built in ip reporting for boot2docker.
Step 5.5. Stopping Docker, Killing Docker
This will give a listing of the running docker instances, so you can
docker kill <name>
Step 6. Docker Hub
One thing that was neato to discover is that knowledge of github / git was translatable to docker. They have designed the usage of Docker Hub around “push” and “pull” concepts. It’s just a matter of pushing images up so they can be pulled down later. What I wasn’t able to find was how to actually send the Dockerfile along with the image. It’s not strictly necessary, but I’ve seen it on other projects, so I know it’s possible…
Getting the container up and running and distributable was no big deal, but this was not enough. Next steps would be to grab a mysql docker image from the hub and have the two communicate with each other. Right now I’m really just using the container as a VM, which isn’t really the point of docker.