Quantcast
Viewing latest article 17
Browse Latest Browse All 36

INCEPTION – A Docker image that build Docker images…

I really like Docker – a very easy way to create runnable containers. I want to show you how you can create a Docker image that build all you Docker images (Inception!).

Use Cases for such a Docker image:

  • Continuous Deployment
  • Environments without build tools (but obviously with docker)
  • because I can

So this docker-inception image should do the following:

  • fetch your application and dockerfiles from a repo
  • setup needed dev tools (nodejs, npm, mvn, ant, gradle…)
  • compile the source
  • build all docker images
  • orchestrate the docker images, for example with fig

-> all but the last tasks are (static) RUN commands, while the orchestrate task is a CMD task that will run if you execute the image.

Here is an example Dockerfile I use:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
FROM dockerfile/nodejs:latest
MAINTAINER Michael Vogt <michu@neophob.com>
WORKDIR /builder

# BUILD ENV VARS
ENV GIT_BRANCHNAME feature-docker-leightweight

# add bitbucket deployment key
ADD assets/ /builder/
RUN chmod 600 /builder/key

# install gem and compass (0.12.6 is available anymore)
RUN apt-get update -qq && apt-get install -yqq --no-install-recommends ruby
RUN gem install compass

# add ssh wrapper to use private key
RUN echo '#!/bin/bash\nssh -i /builder/key -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -o GlobalKnownHostsFile=/dev/null $@' > ./my_git_ssh_wrapper && chmod +x ./my_git_ssh_wrapper

# get source from git repo
RUN GIT_SSH=/builder/my_git_ssh_wrapper git clone git@bitbucket.org:XXX/YYY.git -b $GIT_BRANCHNAME

# install needed build modules
RUN npm install -g grunt-cli@0.1.13 bower@1.3.9

# build
RUN cd XXX/YYY && npm install && bower --allow-root install && grunt build && cd -

# install fig
RUN curl -L https://github.com/docker/fig/releases/download/0.5.2/linux > /usr/local/bin/fig && chmod +x /usr/local/bin/fig

CMD fig up -d

Some comments about this Dockerfile:

  • Asset files: key (SSH Private key) and fig.yml
  • I use bitbucket as git repo, thus the ssh key and the ssh wrapper

Build the docker image:

1
docker build -t build-inception .

Run the docker image:

1
docker run --rm -v /var/run/docker.sock:/var/run/docker.sock -v $(which docker):$(which docker) build-inception

Credits to http://blog.xebia.com/2014/07/04/create-the-smallest-possible-docker-container/.


Viewing latest article 17
Browse Latest Browse All 36

Trending Articles