Skip to content

Dockerfile Code Syntax

Dockerfile SyntaxExplanationExample
FROMSpecifies the base image for subsequent instructionsFROM python:3.9-alpine
LABELAdds metadata to an imageLABEL maintainer="John Doe <john.doe@example.com>"
RUNExecutes a command in the containerRUN pip install -r requirements.txt
CMDSpecifies the default command for the containerCMD ["python", "app.py"]
EXPOSEInforms Docker that the container will listen on the specified network portsEXPOSE 80
ENVSets environment variablesENV FLASK_APP=app.py
COPYCopies files from the host machine to the containerCOPY . /app
ADDCopies files from the host machine to the container, and also supports downloading files from URLs and extracting compressed archivesADD https://example.com/archive.tar.gz /app
WORKDIRSets the working directory for subsequent instructionsWORKDIR /app
ARGDefines build-time variables that can be passed to the Docker build commandARG VERSION=1.0
VOLUMECreates a mount point for external volumesVOLUME /data