Dockerfile
External
Internal
Overview
A Dockerfile is a plain text file that defines how a container should look at build time. It contains all the steps that are required to create the image.
Each line in the Dockerfile generates a new layer in the image. Multiple commands can be combined on a single line, to reduce the number of layers.
The Dockerfile is used as the argument of the docker build command.
Examples
- Dockerfile Example
- A Dockerfile that builds a Centos-based image: https://github.com/NovaOrdis/playground/blob/master/docker/simplest-dockerfile/Dockerfile
Syntax
<instruction> <arguments>
Example
Instructions
Instructions are also known as "directives", and they are part of a DSL.
ADD
Copies files from the local filesystem into the image.
ADD /something/something_else.conf $MY_PATH
CMD
Defines the command that launches the process to be executed in the container.
CMD [ "somehting", "-arg" ]
See:
ENTRYPOINT
FROM
Specifies the base image upon which other layers are built.
FROM node:0.10
If the only Dockerfile instruction is FROM, the build command simply downloads the base image into the local registry, listing the image's repository and tag.
USER
The user to run a container's processes as.
Also see Docker Security
ENV
Declares environment variable accessible to the processes in the container:
ENV SOMETHING "something else"
RUN
Running commands like yum in the Dockerfile is discouraged because it increases the time it takes for the build to finish. The alternative is to use base images that already have these updates applied.
WORKDIR
Changes the working directory within the context of the image being built, for the rest of the build instructions.
MAINTAINER
LABEL
Applies a label to the image.
LABEL "something"="something else" "other label"="some other content"
VOLUME
VOLUME /some/dir
Define a mount point to an external volume on the native host or other containers. The actual location of the volume on the native host is a directory whose path is returned by the corresponding "Source" entry in output of the "inspect -f '{{json .Mounts}}' <container-id>" command.