Docker is revolutionizing virtualization, and arguably cloud computing as a whole. Docker runs everywhere, everywhere where you can run Linux that is. If you are running Linux, you are a quick install away from running the Docker client and daemon natively. But if you are on a Mac or Windows, you have to resort to a Linux virtual machine or remote VPS with Docker installed in order to build Docker images and run Docker containers… or do you?
Side note: There is a native OSX Docker client. Available here.
In this tutorial I’m going to walk you through using Docker, but with one big caveat, we won’t be directly interacting with Docker.
Step 1 – Start with a Dockerfile
A Dockerfile is a text file that can be used to automate the steps you would otherwise take to manually create a Docker image. Everything you need to know about Dockerfiles can be found here. We’re going to use a Dockerfile that we’ve got for a vanilla, out-of-the-box Redis installation. But any other Dockerfile should work just as well. There are a number of public GitHub repositories with Dockerfiles, here we are using one from https://github.com/tutumcloud/tutum-docker-redis
FROM ubuntu:quantal MAINTAINER Fernando Mayo <email@example.com> RUN apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv C7917B12 RUN echo "deb http://ppa.launchpad.net/chris-lea/redis-server/ubuntu quantal main" >> /etc/apt/sources.list RUN apt-get update RUN DEBIAN_FRONTEND=noninteractive apt-get install -y redis-server pwgen # Add scripts ADD https://raw.github.com/tutumcloud/tutum-docker-redis/master/run.sh /run.sh ADD https://raw.github.com/tutumcloud/tutum-docker-redis/master/set_redis_password.sh /set_redis_password.sh RUN chmod 755 /*.sh EXPOSE 6379 CMD ["/run.sh"]
Use your favorite text editor to copy/paste or create and save your Dockerfile locally. (Preferably, name the file Dockerfile).
Step 2 – Build Dockerfile
Now, if we were running the Docker daemon, locally or remotely, we could build the Dockerfile and create a Docker Image. But the whole purpose of this tutorial is to do without Docker. So, instead, we’re going to use a hosted Docker registry called Quay.io
If you haven’t registered already, I encourage you to do so and create a free account at Quay.io You will not regret it, plus they offer an awesome free tier for public repositories.
In Quay.io the first thing we want to do is to create a new repository. Make sure to select “Initialize Repository from Dockerfile.” Choose the Dockerfile we created earlier from your local disk, and click on “Create Repository.”
Cool! You’ve now got you very own image built from the Dockerfile you wrote/copied, and you haven’t even touched a Docker client/daemon yet.
Step 3 – Import Image
Before we are able to run a container from the image we just created, we need to import said image (repository) into Tutum. If you haven’t done so already, now is a good time to create your free account at Tutum.
On the left-panel, go to “Private Registries” then click on “Actions > Manage users” for Quay.io, as shown in the image below.
In the modal that comes up, fill in with your Quay.io credentials, this will enable Tutum to connect to Quay.io and pull the images (repositories) right from Quay’s registry.
Next, on the left-panel, click on “Private Images” and then the button “Add private image”. You’ll get a modal like the one below. You’ll have to add the name of the image (repository) – the name must match the one you created earlier at Quay.io. Finally, just add a description, and click Save.
You should now see the image (repository) from Quay.io listed along with your other Private Images at Tutum.
Great! Now let’s move on to actually launching our container.
Step 4 – Launch Container
In Tutum, click on “Containers” on the left-panel. Then click on the green button that reads “New container”. Since we’ll be using an image from a private registry, click on the last tab from the modal, “Private registry”. You should see the image from Quay.io listed here.
Select the correct tag for this image (most likely it will be “latest”), and click on “Select”. In the next screen you can configure the container by giving it a name, choosing a container size, defining the Docker “run command” and adding/removing ports.
Click “Finish” to launch your new container. You will see your container launching in a matter of seconds (YMMV depending on the size of the image).
Step 6 – Test Container
After your container has successfully started, in order too see the container details, click on the magnifying glass next to the container’s name. From here you can see all of the container’s information, including mapped ports, as well as logs and monitoring information (CPU, Network, Memory, Disk).
We can gather that the hostname for our container is: No-Docker-Redis-borjaburgos.perses.tutum.io and Redis is listening on port: 49180
Furthermore, this particular image of Redis we chose prints the password in the Logs, as shown in the image below:
Step 7 – Conclusion
We have been able to go from zero to running a custom Docker container without directly interacting with the Docker client or daemon, that’s impressive!
There are a number of key features currently under development that will allow you to do more advance deployments, such as container linking, scaling, persistent storage, and tight integration with private registries, such as Quay.io. Recently, we also made our API publicly available, and we will soon be releasing a CLI and accompanying Python Library to interact with Tutum programatically.
To get notified of our next blog post with more Docker tricks and tutorials, and cool and innovative ways to deploy using Tutum’s infrastructure, please sign up at the bottom right corner, or follow us on Twitter at http://twitter.com/tutumcloud.