The Dockerfile for export-server (image-export/Dockerfile) is not good:
FROM node:slim
LABEL maintainer="JGraph Ltd"
RUN apt-get update -y && \
apt-get install -y --no-install-recommends \
git curl software-properties-common chromium libatk-bridge2.0-0 libgtk-3-0 && \
apt-add-repository contrib && \
apt-get update -y && \
apt-get install -y --no-install-recommends \
ttf-mscorefonts-installer && \
mkdir /usr/local/drawio && \
cd /usr/local/drawio && \
git clone https://github.com/jgraph/draw-image-export2.git && \
cd draw-image-export2 && \
npm install && \
apt-get remove -y --purge chromium git
WORKDIR /usr/local/drawio/draw-image-export2
EXPOSE 8000
CMD ["npm", "start"]
Review:
- Label
maintainer is outdated.
Use org.opencontainers.image.*** labels.
- At next, setting the following set of OCI labels will allow for container inspection tools:
...
--label "org.opencontainers.image.title=..." \
--label "org.opencontainers.image.description=..." \
--label "org.opencontainers.image.authors=Firstname Lastname <email@address.com>" \
--label "org.opencontainers.image.vendor=..." \
--label "org.opencontainers.image.version=1.0" \
--label "org.opencontainers.image.revision=${CI_COMMIT_SHA}" \
--label "org.opencontainers.image.created=$(date -u +"%Y-%m-%dT%H:%M:%SZ")" \
--label "org.opencontainers.image.url=${CI_PROJECT_URL}" \
--label "org.opencontainers.image.source=$(printf ${CI_REPOSITORY_URL} | sed 's|//.*@|//|')" \
--label "org.opencontainers.image.documentation=${CI_PROJECT_URL}" \
--label "org.opencontainers.image.license=MIT" \
...
apt-get update and apt-get install exist two times.
Reorder the apt-get commands to void duplications and reduce build time.
- Why is
chromium installed?
It's later uninstalled and obviously no dependency.
- Don't clone source files in a Dockerfile.
Sources are cloned outside of the Docker build process and handed over into the Docker build process via
RUN --mount=type=bind,target=/context:
RUN --mount=type=bind,target=/context \
mkdir -p /tools \
&& cp /context/ToolBox.sh /tools/
- Only copy necessary files into the Docker image. For sure, the Git repository contains unnecessary files.
Specify a .dockerignore file to reduce the visible files in a Docker build context.
- At best specify a list of packages to install in an external file, instead of listing individual dependencies in the Dockerfile.
RUN --mount=type=bind,target=/context \
apt-get update \
&& xargs --no-run-if-empty --exit --arg-file=/context/Install.packages apt-get install -y --no-install-recommends \
&& rm -rf /var/lib/apt/lists/* \
&& apt-get clean
- When removing
chromium and git, the apt caches are not cleaned !
Run rm -rf /var/lib/apt/lists/* and apt-get clean.
The Dockerfile for export-server (image-export/Dockerfile) is not good:
Review:
maintaineris outdated.Use
org.opencontainers.image.***labels.apt-get updateandapt-get installexist two times.Reorder the
apt-getcommands to void duplications and reduce build time.chromiuminstalled?It's later uninstalled and obviously no dependency.
Sources are cloned outside of the Docker build process and handed over into the Docker build process via
RUN --mount=type=bind,target=/context:RUN --mount=type=bind,target=/context \ mkdir -p /tools \ && cp /context/ToolBox.sh /tools/Specify a
.dockerignorefile to reduce the visible files in a Docker build context.chromiumandgit, the apt caches are not cleaned !Run
rm -rf /var/lib/apt/lists/*andapt-get clean.