Featured image of post DockerFile Cheatsheet

DockerFile Cheatsheet

Cheatsheet of Dockerfile commands

Dockerfile Cheatsheet

InstructionSyntax/ExampleDescription
FROMFROM ubuntu:20.04Specifies the base image
RUNRUN apt-get update && apt-get install -y python3Executes a command in the shell during the build process
COPYCOPY . /appCopies files from the host to the container
ADDADD https://example.com/file.tar.gz /app/Similar to COPY but can also retrieve remote files and unpack archives
WORKDIRWORKDIR /appSets the working directory for the RUN, CMD, ENTRYPOINT, COPY and ADD instructions
CMDCMD ["python3", "app.py"]Provides the default command to run the container
ENTRYPOINTENTRYPOINT ["python3", "app.py"]Configures the container to run as an executable
ENVENV APP_ENV=productionSets environment variables
EXPOSEEXPOSE 80Informs Docker that the container listens on the specified network ports at runtime
VOLUMEVOLUME /dataCreates a mount point with the specified path and marks it as holding externally mounted volumes
USERUSER appuserSets the user name or UID to use when running the image
LABELLABEL version="1.0"Adds metadata to the image
ARGARG VERSION=1.0Defines a variable that users can pass at build-time to the builder with the docker build command
ONBUILDONBUILD RUN apt-get updateAdds a trigger instruction to be executed when the image is used as a base for another build
STOPSIGNALSTOPSIGNAL SIGKILLSets the system call signal that will be sent to the container to exit
HEALTHCHECKHEALTHCHECK –interval=30s CMD curl –fail http://localhostTells Docker how to test that the container is still working