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.
Dockership introduces a serie of variables into the Dockerfiles. This could be very useful in some cases.
This kind of variables are sourced from the internal process of Dockerfile given info about the deploy action.
$DOCKERSHIP_PROJECT: Project name
$DOCKERSHIP_VCS: Repository URLs, the
Repositoryvariable from the project.
$DOCKERSHIP_REV: Revision identifier
$DOCKERSHIP_ENV: Environment name where the Dockerfile is being deployed.
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
$ETCD_QUX__BAR. If the key is not found or
etcd returns an error, the variable is not replaced.
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
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