Docker is a popular containerization platform that allows developers to package their applications and dependencies into a single container. Docker containers are lightweight, portable, and can run on any platform that supports Docker. Dockerfile is a script that contains a set of instructions to build a Docker image. In this article, we will introduce some of the most commonly used Dockerfile commands.
This cheat sheet provides a list of Dockerfile commands and their descriptions.
Base Image Commands
Command
Description
FROM
Specifies the base image for the Dockerfile
MAINTAINER
Specifies the name and email address of the person maintaining the Dockerfile
Environment Commands
Command
Description
ENV
Sets environment variables in the container
ARG
Defines arguments that can be passed to the Dockerfile at build time
Run Commands
Command
Description
RUN
Executes a command in the container
CMD
Specifies the default command to run when the container starts
ENTRYPOINT
Specifies the command to run when the container starts, and any arguments passed to the container are appended to this command
Copy Commands
Command
Description
COPY
Copies files from the host machine to the container
ADD
Copies files from the host machine to the container, and can also extract archives
Expose Commands
Command
Description
EXPOSE
Exposes a port from the container to the host machine
Volume Commands
Command
Description
VOLUME
Creates a mount point for a volume in the container
User Commands
Command
Description
USER
Sets the user or UID that the container runs as
Workdir Commands
Command
Description
WORKDIR
Sets the working directory for any RUN, CMD, ENTRYPOINT, COPY, and ADD commands
Reference
For more information on Dockerfile commands, please refer to the official Docker documentation: https://docs.docker.com/engine/reference/builder/