Last active
September 8, 2023 14:20
-
-
Save iagoalonsomrf/d4348c7617dc337531334ba5f0131d21 to your computer and use it in GitHub Desktop.
Best practices for writing Dockerfiles
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ARG DEBIAN_FRONTEND=noninteractive | |
# Tags should be as specific as possible | |
FROM ubuntu:jammy-20220815 | |
# Set default locale in UTF-8 enabled mode | |
ENV LANG=C.UTF-8 | |
# Add metadata to the image | |
LABEL maintainer="[email protected]" | |
# Use diff-friendly syntax for multi-line commands | |
# Do not install non-necessary packages | |
# Sort dependencies | |
# Clean non-necessary files after installing dependencies | |
RUN : \ | |
&& apt-get update \ | |
&& apt-get install --no-install-recommends -y \ | |
curl \ | |
python3 \ | |
python3-pip \ | |
sl \ | |
&& apt-get clean \ | |
&& rm -rf /var/lib/apt/lists/* \ | |
&& : | |
# Do not cache Python dependencies | |
# Sort dependencies | |
RUN : \ | |
&& python3 -m pip --no-cache-dir install \ | |
pre-commit \ | |
virtualenv \ | |
&& : | |
# Create non-privileged user | |
RUN : \ | |
&& groupadd --gid 1001 marfeel \ | |
&& useradd --uid 1001 --gid marfeel --system --create-home --home-dir /home/marfeel marfeel \ | |
&& : | |
# Do not use an extra step to change ownership of files | |
COPY --chown=marfeel:marfeel Dockerfile /Dockerfile | |
# Set non-privileged user as default | |
USER marfeel | |
# Define the default script | |
ENTRYPOINT ["/bin/echo"] | |
# Define the default arguments | |
CMD ["Hello from Docker"] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
TODO: AddCMD
andENTRYPOINT