Creating your Dockerfiles

This documentation assumes that you know what is a Dockerfile and how to define one, if not please take a look to the Dockerfile Reference before to continue.

Those variables are replaced by Dockership before being submitted to the Docker server.

Variables

Dockership introduces a serie of variables into the Dockerfiles. This could be very useful in some cases.

Deployment information

This kind of variables are sourced from the internal process of Dockerfile given info about the deploy action.

etcd support

Dockership can be connected to a etcd server and allowing retrieve values directly into your Dockerfile.

The etcd keys are translated to variables. For example a key called FOO will be converted in $ETCD_FOO or a key in a directory like QUX/BAR becomes $ETCD_QUX__BAR. If the key is not found or etcd returns an error, the variable is not replaced.

The etcd keys are case-sensitive, to replace a key named foo a variable $ETCD_foo is required. If the key is a directory the / should be replace with __.

Avoid cache issues

For the most part, the image cache is incredibly helpful saving us a lot of time. However, this becomes tricky when the command results differs on each call.

Let’s say we have the following Dockerfile:

FROM ubuntu:14.04

RUN apt-get update
RUN apt-get install -y build-essential git

RUN git clone https://github.com/mcuadros/flask-example.git
WORKDIR flask_example
RUN python setup.py install

The first time we build this all works as expected the mcuadros/flask-example is fletched with the latest version.

But then a developer commits something new to this repository and we want to build the new image version and the result is:

Step 3 : RUN git clone https://github.com/mcuadros/flask-example.git
 ---> Using cache
 ---> 2caac4df5e4a

This is very inconvenient since the builded image still has the old code. The most common option is to use the NoCache options ignoring the cache generated by the first build, but in this case every time we build the image apt-get update and apt-get install -y build-essential git will be executed being a suboptimal solution.

We propose to use $DOCKERSHIP_REV at the same RUN command. Now, if the version has changed, the cache will be ignored retrieving the new content.

FROM ubuntu:14.04

RUN apt-get update
RUN apt-get install -y build-essential git

RUN git clone https://github.com/mcuadros/flask-example.git && echo $DOCKERSHIP_REV
WORKDIR flask_example
RUN python setup.py install