ProSheet 09 of 11
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
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
| Instruction | Purpose | Example |
|---|---|---|
FROM | Base image | FROM ubuntu:22.04 |
RUN | Execute a command | RUN apt update && apt install -y nginx |
COPY | Copy files from host | COPY . /app |
ADD | Copy with additional features | ADD https://example.com/file.tar.gz /tmp/ |
WORKDIR | Set working directory | WORKDIR /app |
CMD | Default command | CMD ["nginx", "-g", "daemon off;"] |
ENTRYPOINT | Main command | ENTRYPOINT ["python"] |
EXPOSE | Document ports | EXPOSE 80 |
ENV | Environment variable | ENV NODE_ENV=production |
ARG | Build-time variable | ARG VERSION=latest |
LABEL | Metadata | LABEL maintainer="me@example.com" |
VOLUME | Mount point | VOLUME /data |
USER | Set user | USER www-data |
HEALTHCHECK | Health check | HEALTHCHECK --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"]