A Dockerfile is a scripted file completely unique to docker. It’s primary purpose is to instruct Docker on how to build an image. It contains all the commands a user could call on to assemble an image. Each docker file is separated into several distinct instructions:
Instruction | Description |
---|---|
FROM | The first non-comment instruction in the Dockerfile. It is required in all Dockerfiles. It instructs docker on which base image to use for the new image. It is usually a minimal distribution of Linux. |
MAINTAINER | This is the author field for an image. It notifies viewers to whom will maintain the image. |
RUN | This runs specified commands in a shell on the base image. This is useful for installing software or running updates to package managers after the container is started. Using && s in a single RUN instruction allow you to execute multiple commands on a single layer. |
CMD | This is a required instruction that must be at the end of the file.There can only be one CMD instruction in a Dockerfile. It is primary to provide defaults for an executing container. It is the final command that will run every time you launch a new container from the image or every time you restart a “stopped” container. |
LABEL | This adds metadata to an image. |
EXPOSE | This informs docker that the container listens on the specified port(s) at runtime. |
ENV | This sets an environment variable key to a value. Order matters since the file is read from top to bottom. |
ADD | This copies new files, directories, or remote file URLs from a source and adds them to the file system of the image. |
COPY | This copies new files or directories from a source and adds them to the file system of the image. |
ENTRYPOINT | This allows you to configure a container that will run as an executable. |
VOLUME | This creates a mount point with the specified name and marks it as holding externally mounted volumes from a native host or another container. |
USER | This sets the username or UID to use when running the image. It also sets these parameters for any RUN, CMD, and ENTRYPOINT instruction that follow this instruction in the Dockerfile. |
WORKDIR | This sets the working directory for any RUN, CMD, ENTRYPOINT, COPY, and ADD instruction that follow it. |
ARG | This defines a variable that users can pass at build-time to the builder with the docker build command using the --build-arg flag. |
ONBUILD | This adds to the image a trigger instruction to be executed at a later time, when the image is used as the base image for another build. |
STOPSIGNAL | This sets the system call signal that will be sent to the container to exit. |
HEALTHCHECK | This tells docker how to test a container to check that it is still working. |
SHELL | This allows the default shell used for the shell form of commands to be overridden. |