If a service can run without privileges, use USER to change to a non-root user.
Dockerfile (Workdir)
Kind of like a cd. Changes current working directory to that which is specified.
Dockerfile (Volume)
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. A LOT of information about volumes can be found here.
VOLUME <mountpoint>
Dockerfile (Expose)
The EXPOSE instruction informs Docker that the container listens on the specified network ports at runtime. You can specify whether the port listens on TCP or UDP, and the default is TCP if the protocol is not specified. To actually publish the port when running the container, use the -p or -P flag on docker run.
Dockerfile (Expose)
EXPOSE <port> [<port>/<protocol>...]
EXPOSE 8080
This will expose 8080 tcp port.
Dockerfile (RUN)
RUN <command> (or)
RUN ["executable", "param1", "param2"]
The first command is a shell command always executed at build.
The second does not automatically invoke shell /bin/sh -c.
It is nice to put the run command all in one line because each time you invoke the RUN command a new layer is created. See layers with docker history foo (assuming foo is an image). Could add to image size. More about layers.
Dockerfile (CMD)
RUN executes at build time, CMD executes when the container is launched.
If you want to run your <command> without a shell then you must express the command as a JSON array and give the full path to the executable. This array form is the preferred format of CMD. Any additional parameters must be individually expressed as strings in the array:
FROM ubuntu
CMD ["/usr/bin/wc","--help"]
Dockerfile (CMD)
Syntactically, you can add more than one CMD instruction in Dockerfile. However, the build system would ignore all the CMD instructions except for the last one. In other words, in the case of multiple CMD instructions, only the last CMD instruction would be effective.
Dockerfile (ENTRYPOINT)
The best use for ENTRYPOINT is to set the image’s main command, allowing that image to be run as though it was that command (and then use CMD as the default flags).