From charlesreid1

The Dockerfile is where you define the commands that populate your docker container.

Crafting Dockerfiles

The Philosophy

The idea is to have easy to start and easy to stop services that are stateless, and don't "expect" stuff. (Not sure I understand that exactly, but okay.)

Web app stack example: LAMP would implement Apache as one container, MySQL as another, and PHP as another (well, maybe A+P as one.)

Maybe one container for a cache, too.

Keep em clean, keep em modular.

Copy command

Copy command allows you to copy stuff from local host system into the docker image.

Add command works too, but copy less complicated.

https://docs.docker.com/engine/reference/builder/#copy

Finding Dockerfile examples

The dockerfiles used to create various docker images are usually available with the image itself and are usually quite simple. That's the idea, anyway.

For example, here's an uncomplicated Dockerfile for an Stunnel docker container from [1]:

FROM ubuntu
RUN apt-get update
RUN apt-get -y install stunnel
CMD ["stunnel"]

To build custom versions, this dockerfile [2] might be better:

# stunnel Server
#
# VERSION 0.0.1

# Building from Ubuntu Precise
FROM ubuntu:precise

MAINTAINER Courtney Couch, courtney@moot.it

RUN apt-get update
RUN apt-get upgrade -y

RUN apt-get -y install build-essential wget
RUN apt-get -y install openssl libssl-dev

ENV STUNNEL_VERSION 4.56

RUN wget -O - ftp://ftp.stunnel.org/stunnel/archive/4.x/stunnel-$STUNNEL_VERSION.tar.gz | tar -C /usr/local/src -zxv

RUN mkdir -p /stunnel
VOLUME ["/stunnel"]

ADD stunnel.conf /stunnel/stunnel.conf
ADD stunnel.pem /stunnel/stunnel.pem

# Build stunnel
RUN cd /usr/local/src/stunnel-$STUNNEL_VERSION && ./configure && make && make install

EXPOSE 443

CMD ["/usr/local/bin/stunnel", "/stunnel/stunnel.conf"]


Building Containers with Dockerfiles

Use the docker build command. Specify the name of the image with -t and specify the location of the Dockerfile. Here is an example, checking out a tiny repo with a single dockerfile:

$ mkdir ~/docker
$ cd ~/docker
$ git clone https://charlesreid1.com:3000/docker/d-stunnel.git
$ cd d-stunnel

Now that we are all ready:

$ docker build -t cmr_stunnel .

This creates an stunnel container ready to go in docker, which can be seen by running docker images.

$ docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
cmr_stunnel         latest              2b197f506e02        59 seconds ago      219 MB

Flags