Dockerfile Cheat Sheet¶
FROM
: Specifies the base image to use for the build.RUN
: Runs a command during the build process.COPY
: Copies files or directories from the host machine to the container.ENV
: Sets an environment variable in the container.EXPOSE
: Exposes a port or ports to be used by the container.ENTRYPOINT
: Specifies the command to run when the container starts.CMD
: Specifies default arguments for theENTRYPOINT
command.USER
: Sets the user and group to run the container as.WORKDIR
: Sets the working directory for commands run in the container.VOLUME
: Creates a mount point for a volume in the container.
Example:
FROM alpine
RUN apk update && apk add python3
COPY myfile.txt /app
ENV MY_ENV_VAR=value
EXPOSE 8080
ENTRYPOINT ["python3"]
CMD ["app.py"]
USER 1001
WORKDIR /app
VOLUME /data
Note: Always try to use specific version of base images and package to avoid any unexpected behaviour.
Other cheat sheets and official doc¶
- https://kapeli.com/cheat_sheets/Dockerfile.docset/Contents/Resources/Documents/index
- https://docs.docker.com/engine/reference/builder/
Page last modified: 2024-09-25 08:35:47