One page

Docker basics cheat sheet

What to keep at hand. If a line is not clear, go back to the matching lesson in the course.

Open the course: Docker basics

Containers

WhatHow
Run in the background with a portdocker run -d --name web -p 8080:80 nginx
One-off commanddocker run --rm -it node:22 sh
List containersdocker ps -a
Live logsdocker logs -f --tail 100 web
Get a shell insidedocker exec -it web sh
Stop and removedocker rm -f web

Images and Dockerfile

WhatHow
Build with a tagdocker build -t api:1.0.0 .
Without cachedocker build --no-cache -t api:1.0.0 .
Image layersdocker history api:1.0.0
Copy files (not ADD)COPY . .
Start commandCMD ["node", "server.js"]
No rootUSER node

Volumes and networks

WhatHow
Named volume-v pgdata:/var/lib/postgresql/data
Bind mount-v "$(pwd)":/app
Network with DNSdocker network create app-net
Port on localhost only-p 127.0.0.1:5432:5432
Clean up unuseddocker system prune

Compose

WhatHow
Build and rundocker compose up -d --build
Service statedocker compose ps
Service logsdocker compose logs -f web
Wait until readycondition: service_healthy
Stop (volumes stay)docker compose down

Other cheat sheets