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

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

Environment Commands

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

Run Commands

CommandDescription
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

CommandDescription
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

CommandDescription
EXPOSEExposes a port from the container to the host machine

Volume Commands

CommandDescription
VOLUMECreates a mount point for a volume in the container

User Commands

CommandDescription
USERSets the user or UID that the container runs as

Workdir Commands

CommandDescription
WORKDIRSets 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/