Dockerfile Commands Cheat Sheet

In Docker

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

FROMSpecifies the base image for the Dockerfile
MAINTAINERSpecifies the name and email address of the person maintaining the Dockerfile

Environment Commands

ENVSets environment variables in the container
ARGDefines arguments that can be passed to the Dockerfile at build time

Run Commands

RUNExecutes a command in the container
CMDSpecifies the default command to run when the container starts
ENTRYPOINTSpecifies the command to run when the container starts, and any arguments passed to the container are appended to this command

Copy Commands

COPYCopies files from the host machine to the container
ADDCopies files from the host machine to the container, and can also extract archives

Expose Commands

EXPOSEExposes a port from the container to the host machine

Volume Commands

VOLUMECreates a mount point for a volume in the container

User Commands

USERSets the user or UID that the container runs as

Workdir Commands

WORKDIRSets the working directory for any RUN, CMD, ENTRYPOINT, COPY, and ADD commands


For more information on Dockerfile commands, please refer to the official Docker documentation: