Docker Cheat Sheet
Docker Cheat Sheet
Docker Cheat Sheet
© Nic Wortel, Software Consultant & Trainer - Last updated on March 8, 2024 - Find more cheat sheets at https://nicwortel.nl/cheat-sheets
Dockerfile instructions Docker Compose file reference
Instruction Description Key Description
FROM <image> Set the base image name Set the name of the project
FROM <image> AS <name> Set the base image and name the build stage services A list of services defined in the file
RUN <command> Execute a command as part of the build process services.<name>.image Set the image to use or build
RUN ["exec", "param1", "param2"] Execute a command as part of the build process services.<name>.build Build context and options
CMD ["exec", "param1", "param2"] Execute a command when the container starts services.<name>.build.context Build context (default is the current directory)
ENTRYPOINT ["exec", "param1"] Configure the container to run as an executable services.<name>.build.dockerfile Dockerfile to use (default is Dockerfile)
ENV <key>=<value> Set an environment variable services.<name>.build.target Build stage to use
EXPOSE <port> Expose a port services.<name>.build.args Build arguments
COPY <src> <dest> Copy files from source to destination services.<name>.command Override the default command for the container
COPY --from=<name> <src> <dest> Copy files from a build stage to destination services.<name>.entrypoint Override the default entrypoint for the container
WORKDIR <path> Set the working directory services.<name>.volumes Mount volumes in the container
VOLUME <path> Create a mount point services.<name>.ports Publish container ports to the host
USER <user> Set the user services.<name>.environment Set environment variables in the container
ARG <name>=<default> Define a build argument with a default value services.<name>.scale Set the number of containers to run
LABEL <key>=<value> Set a metadata label services.<name>.networks List of networks to connect the container to
HEALTHCHECK <command> Set a healthcheck command services.<name>.depends_on List of services to start before this service
services.<name>.labels Set metadata labels for the container
See https://docs.docker.com/engine/reference/builder/ for the full Dockerfile reference.
networks A list of networks defined in the file
© Nic Wortel, Software Consultant & Trainer - Last updated on March 8, 2024 - Find more cheat sheets at https://nicwortel.nl/cheat-sheets