Docker¶
Based on the Docker guidelines
General¶
- A
.dockerignorefile 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.
Dockerfile¶
- Multi-line arguments SHOULD be sorted.
- The number of layers SHOULD be kept to a minimum.
-
A single
RUNcommand 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
RUNcommand:RUN apk add --virtual .deps \ gcc make \ && make \ && ./configure \ && apl del .deps \ && rm -rf /path/to/installer -
You SHOULD use
set -xeto print commands and stop on any errors as the first commandRUN set -xe \ && do stuff \ && tidy
-
-
Multiple line
LABELs should use line-continuation characters to break linesLABEL maintainer="developers@graze.com" \ license="MIT" -
The
MAINTAINERcommand SHOULD NOT be used (useLABEL maintainerinstead). - The
LICENSEcommand SHOULD NOT be used (useLABEL licenseinstead). -
Label Schema labels SHOULD be used.
- If using, a
org.label-schema.schema-versionlabel MUST be defined. -
The
vendor,name,descriptionandvcs-urllabels 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-refandbuild-datelabels SHOULD be generated. Example:ARG BUILD_DATE ARG VCS_REF LABEL org.label-schema.vcs-ref=$VCS_REF \ org.label-schema.build-date=$BUILD_DATEThis can then be injected into the image using the
--build-argargument~$ 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 .
- If using, a
-
COPYSHOULD be used instead ofADDfor simple files. CMDSHOULD be used with the array syntax:["executable", "param1", "param2", ...].- All ports SHOULD be included with
EXPOSEcommands. - Any volumes that are mutable or user-servicable SHOULD use a
VOLUMEcommand.