Wednesday, July 29, 2015

Portability Series: Usage of a Debian Base Image: compose

So we have created a Debian base image and are looking at some of the steps to run containers which may have platform dependencies. An example which brings this together is one of the Docker ecosystem components: compose. Docker compose lets you define applications which consist of several containers. You can the manage your entire multi-container application with single commands.
Let's get the code for compose:

git clone
You can check out tags on the project's github page to get a specific or stable version. I picked the latest and greatest from master branch for this flow, but it is the same for older versions, too. So we have a compose directory with a lot of files, including a Dockerfile. The Dockerfile starts with basing off debian:wheezy. So we first get a debian:wheezy as described in the previous post.

What else happens in the Dockerfile? A lot of packages are installed using apt-get. Python is downloaded, built and installed. Some setuptool is dowloaded and executed. pip, a python package management tool is downloaded, built and installed.

Then, a list of Docker versions is pushed into an environment variable, and binaries for these versions are downloaded and installed. Ok, this is different for s390x, at least for now. So we change the version setting to 1.6.0, because that's out there for s390 (note to myself... need to update this short term). The downloadable comes from a different path and is a tarball. I used this code:

RUN set -ex; \
    curl -LO; \
    tar xzf docker-rhel7-20150509.tar.gz; \
    cp docker-rhel7-20150509/docker /usr/local/bin/docker-1.6.0; \
    chmod +x /usr/local/bin/docker-1.6.0

# Set the default Docker to be run
RUN ln -s /usr/local/bin/docker-1.6.0 /usr/local/bin/docker
Alternatively to the curl-tar-cp-chmod combination, you could copy your Docker executable into the compose directory and say
ADD docker-1.6.0 /usr/local/bin/

The Dockerfile continues. pip and python stuff, and the definition of the entry point -- this will be executed when the container is started. We're through, let's build the image with
docker build -t compose compose
So we now have a container for compose -- but if you look around, every tutorial uses the command docker-compose. There are several approaches to come to this: One, don't even go the container route and perform the installation in the host system. The /usr/local/bin/docker-compose is a python script and is simply executed. Or, two, following our container route, everything is nicely wrapped in a container and we only need to invoke it appropriately. The right script comes with the compose package: copy compose/script/dev into /usr/local/bin and rename it to docker-compose. Remove the line starting with "docker build", since the development script automatically checks for changes in the code and builds them. This script passes directories to the container to make it read the compose yaml file and behave like the original docker-compose script inside the container.
The project home page explains on the rich usage options of compose. Have fun with your compositions.

No comments:

Post a Comment