Vous êtes ici

First steps with Docker - 3

dockerPrevious article

Using a Dockerfile

Let's try now to write a Dockerfile that builds the same Apache image than the one we committed in previous article.

After a few trials and errors, the simplest Dockerfile I was able to create is this one:

FROM ubuntu:14.04

MAINTAINER <name> <<email>>

RUN DEBIAN_FRONTEND=noninteractive apt-get update && apt-get install -y \
    apache2 \
    libapache2-mod-php5 \
    nano \
    php5 \


ENTRYPOINT ["/usr/sbin/apache2ctl","-DFOREGROUND"]

In a first test, I tried to modify the policy-rc.d file, as I did previously. But it appeared that it was not required.

The DEBIAN_FRONTEND=noninteractive definition is there only to prevent apt-get from displaying warning messages.

The -DFOREGROUND parameter tells Apache to run parent process in foreground, so that the container will not end execution right after it is launched.

To create the image from this file:

  • create a directory, cd to this directory, put the above file there, naming it Dockerfile
  • build the image with the following command:
docker build -t="<userid>/apache2:v1" .
  • then, to run resulting image:
docker run -p 80:80 -d <userid>/apache2:v1

The -d option tells Docker to run the container in the background.

To get a list of running containers: docker ps

To stop the container, use the id displayed above in the command: docker stop <containerId>

So, here we are: we got a working image, on the development machine, built thanks to a Dockerfile.

From the development machine to the production machine

Instead of transferring the image to my server (the "production machine"), I transfer the Dockerfile, and build the image on the production machine. As I already have a running web server there, I need to provide another port mapping when running the container:

docker run -p 8080:80 -d <userid>/apache2:v1

The container web server will be reachable on port 8080.

Next article