New batchZero to DevOps starts 29 Nov · limited seatsReserve your seat
Cheat sheetsDockerDocker
ProSheet 09 of 11

Docker Images & Dockerfile

A comprehensive developer cheatsheet covering Dockerfiles and image registries, featuring essential instructions, CLI commands, and operational workflows for writing Dockerfiles, building multi-stage images, archiving, tagging, pushing, and pulling images.

Understanding Dockerfile

What is a Dockerfile?

A Dockerfile is a text file containing instructions to build a Docker image.

Common Dockerfile Instructions

InstructionPurposeExample
FROMBase imageFROM ubuntu:22.04
RUNExecute a commandRUN apt update && apt install -y nginx
COPYCopy files from hostCOPY . /app
ADDCopy with additional featuresADD https://example.com/file.tar.gz /tmp/
WORKDIRSet working directoryWORKDIR /app
CMDDefault commandCMD ["nginx", "-g", "daemon off;"]
ENTRYPOINTMain commandENTRYPOINT ["python"]
EXPOSEDocument portsEXPOSE 80
ENVEnvironment variableENV NODE_ENV=production
ARGBuild-time variableARG VERSION=latest
LABELMetadataLABEL maintainer="me@example.com"
VOLUMEMount pointVOLUME /data
USERSet userUSER www-data
HEALTHCHECKHealth checkHEALTHCHECK --interval=30s CMD curl -f http://localhost/

Sample Dockerfile (Node.js Application)

dockerfile
# Base image
FROM node:18-alpine

# Set working directory
WORKDIR /app

# Copy package files
COPY package*.json ./

# Install dependencies
RUN npm install --production

# Copy application code
COPY . .

# Expose port
EXPOSE 3000

# Set environment variables
ENV NODE_ENV=production

# Health check
HEALTHCHECK --interval=30s --timeout=5s --retries=3 \
  CMD curl -f http://localhost:3000/health || exit 1

# Start application
CMD ["node", "server.js"]

Sample Dockerfile (Python Application)

The rest of this sheet is locked7 Pro sheets unlock together, across every toolEveryPro sheet, every toolLifetimeone payment, no renewalNewsheets included as they shipOne-time payment · lifetime access