Dockerfile Reference
A Dockerfile must begin with a FROM
instruction.
Instructions are not case sensitive.
Parser directives:
Parser directives are optional
Parser directives do not add layers to the build
#directive = value
Environmnet variables:
Environment variables are declared with ENV statement
For example:
ENV abc=hello
ENV foo bar
Environment variables are accessed with ${variable_name} or $variable_name
Environment variables are supported by the following list of instructions.
ADD,COPY,ENV,EXPOSE,FROM,LABEL,STOPSIGNAL,USER,VOLUME,WORKDIR
.dockerignore file
Similar to .gitignore
FROM:
The FROM instruction initializes a new build stage and sets the Base Image for subsequent instructions.
FROM
RUN:
RUN has 2 forms:
RUN
RUN [“executable”, “param1”, “param2”] (exec form)
The RUN instruction will execute any commands in a new layer on top of the current image and commit the results. The resulting committed image will be used for the next step in the Dockerfile.
CMD:
The CMD instruction has three forms:
CMD [“executable”,”param1”,”param2”] (exec form, this is the preferred form)
CMD [“param1”,”param2”] (as default parameters to ENTRYPOINT)
CMD command param1 param2 (shell form)
There can only be one CMD instruction in a Dockerfile. If you list more than one CMD then only the last CMD will take effect.
The main purpose of a CMD is to provide defaults for an executing container.
Note: Don’t confuse RUN with CMD. RUN actually runs a command and commits the result; CMD does not execute anything at build time, but specifies the intended command for the image.
LABEL:
LABEL
MAINTAINER:
MAINTAINER
EXPOSE:
EXPOSE
ADD:
ADD [–chown=
COPY:
COPY [–chown=
ENTRYPOINT:
ENTRYPOINT has two forms
ENTRYPOINT [“executable”, “param1”, “param2”] (exec form)
ENTRYPOINT command param1 param2 (shell form)
Note: Dockerfile should specify at least one of CMD or ENTRYPOINT commands.
VOLUME:
VOLUME [“/data”]
The VOLUME instruction creates a mount point with the specified name and marks it as holding externally mounted volumes from native host or other containers
Create a Volume & mount it from Docker CLI:
docker volume create my-vol
docker volume ls
docker volume inspect my-vol
docker run -d –name devtest –mount source=myvol,target=/app nginx:latest
USER:
USER
WORKDIR:
WORKDIR /path/to/workdir
The WORKDIR instruction sets the working directory for any RUN, CMD, ENTRYPOINT, COPY and ADD instructions that follow it in the Dockerfile
ARG:
ARG
ONBUILD:
ONBUILD [INSTRUCTION]
The ONBUILD instruction adds to the image a trigger instruction to be executed at a later time, when the image is used as the base for another build.
STOPSIGNAL:
STOPSIGNAL signal
HEALTHCHECK:
The HEALTHCHECK instruction has 2 forms
HEALTHCHECK [OPTIONS] CMD command (check container health by running a command inside the container)
HEALTHCHECK NONE (disable any healthcheck inherited from the base image)
SHELL:
SHELL [“executable”, “parameters”]
The SHELL instruction allows the default shell used for the shell form of commands to be overridden.
Leave a comment