preferred form of CMD. All additional parameters must be individually expressed
as strings in the array:
**FROM ubuntu**
**CMD ["/usr/bin/wc","--help"]**
To make the container run the same executable every time, use ENTRYPOINT in
combination with CMD.
If the user specifies arguments to docker run, the specified commands override
the default in CMD.
Do not confuse **RUN** with **CMD**. RUN runs a command and commits the result. CMD
executes nothing at build time, but specifies the intended command for the
image.
**EXPOSE**
--**EXPOSE <port> [<port>...]**
The **EXPOSE** instruction informs Docker that the container listens on the
specified network ports at runtime. Docker uses this information to
interconnect containers using links, and to set up port redirection on the host
system.
**ENV**
--**ENV <key><value>**
The ENV instruction sets the environment variable <key> to
the value <value>. This value is passed to all future RUN instructions. This is
functionally equivalent to prefixing the command with **<key>=<value>**. The
environment variables that are set with ENV persist when a container is run
from the resulting image. Use docker inspect to inspect these values, and
change them using docker run **--env <key>=<value>.**
Note that setting Setting **ENV DEBIAN_FRONTEND noninteractive** may cause
unintended consequences, because it will persist when the container is run
interactively, as with the following command: **docker run -t -i image bash**
**ADD**
--**ADD <src><dest>** The ADD instruction copies new files from <src> and adds them
to the filesystem of the container at path <dest>. <src> must be the path to a
file or directory relative to the source directory that is being built (the
context of the build) or a remote file URL. <dest> is the absolute path to
which the source is copied inside the target container. All new files and
directories are created with mode 0755, with uid and gid 0.
**ENTRYPOINT**
--**ENTRYPOINT** has two forms: ENTRYPOINT ["executable", "param1", "param2"]
(This is like an exec, and is the preferred form.) ENTRYPOINT command param1
param2 (This is running as a shell.) An ENTRYPOINT helps you configure a
container that can be run as an executable. When you specify an ENTRYPOINT,
the whole container runs as if it was only that executable. The ENTRYPOINT
instruction adds an entry command that is not overwritten when arguments are
passed to docker run. This is different from the behavior of CMD. This allows
arguments to be passed to the entrypoint, for instance docker run <image> -d
passes the -d argument to the ENTRYPOINT. Specify parameters either in the
ENTRYPOINT JSON array (as in the preferred exec form above), or by using a CMD
statement. Parameters in the ENTRYPOINT are not overwritten by the docker run
arguments. Parameters specifies via CMD are overwritten by docker run
arguments. Specify a plain string for the ENTRYPOINT, and it will execute in
/bin/sh -c, like a CMD instruction:
FROM ubuntu
ENTRYPOINT wc -l -
This means that the Dockerfile's image always takes stdin as input (that's
what "-" means), and prints the number of lines (that's what "-l" means). To
make this optional but default, use a CMD:
FROM ubuntu
CMD ["-l", "-"]
ENTRYPOINT ["/usr/bin/wc"]
**VOLUME**
--**VOLUME ["/data"]**
The VOLUME instruction creates a mount point with the specified name and marks
it as holding externally-mounted volumes from the native host or from other
containers.
**USER**
-- **USER daemon**
The USER instruction sets the username or UID that is used when running the
image.
**WORKDIR**
-- **WORKDIR /path/to/workdir**
The WORKDIR instruction sets the working directory for the **RUN**, **CMD**, and **ENTRYPOINT** Dockerfile commands that follow it.
It can be used multiple times in a single Dockerfile. Relative paths are defined relative to the path of the previous **WORKDIR** instruction. For example: