Based on the Docker guidelines
- A
.dockerignore
file SHOULD be used - This will ensure the amount of data sent to the docker daemon will be minimal. - Each container SHOULD have a single concern.
-
Multi-line arguments SHOULD be sorted.
-
The number of layers SHOULD be kept to a minimum.
-
A single
RUN
command can contain many commands:-
Use
\
and&&
for multiple commands, with&&
on the new line:RUN cmd \ && cmd2
-
When adding build time packages, remove them in the same
RUN
command:RUN apk add --virtual .deps \ gcc make \ && make \ && ./configure \ && apl del .deps \ && rm -rf /path/to/installer
-
You SHOULD use
set -xe
to print commands and stop on any errors as the first commandRUN set -xe \ && do stuff \ && tidy
-
-
Multiple line
LABEL
s should use line-continuation characters to break linesLABEL maintainer="[email protected]" \ license="MIT"
-
The
MAINTAINER
command SHOULD NOT be used (useLABEL maintainer
instead). -
The
LICENSE
command SHOULD NOT be used (useLABEL license
instead). -
Label Schema labels SHOULD be used.
-
If using, a
org.label-schema.schema-version
label MUST be defined. -
The
vendor
,name
,description
andvcs-url
labels SHOULD be defined.LABEL org.label-schema.schema-version="1.0" \ org.label-schema.vendor="graze" \ org.label-schema.name="project-name" \ org.label-schema.description="project description" \ org.label-schema.vcs-url="https://github.com/graze/docker-project-name"
-
The
vcs-ref
andbuild-date
labels SHOULD be generated. Example:ARG BUILD_DATE ARG VCS_REF LABEL org.label-schema.vcs-ref=$VCS_REF \ org.label-schema.build-date=$BUILD_DATE
This can then be injected into the image using the
--build-arg
argument~$ docker build --build-arg BUILD_DATE=$(date -u +"%Y-%m-%dT%H:%M:%SZ") \ --build-arg VCS_REF=$(git rev-parse --short HEAD) \ -t graze/project-name .
-
-
COPY
SHOULD be used instead ofADD
for simple files. -
CMD
SHOULD be used with the array syntax:["executable", "param1", "param2", ...]
. -
All ports SHOULD be included with
EXPOSE
commands. -
Any volumes that are mutable or user-servicable SHOULD use a
VOLUME
command.