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 basicsContainers
| What | How |
|---|---|
| Run in the background with a port | docker run -d --name web -p 8080:80 nginx |
| One-off command | docker run --rm -it node:22 sh |
| List containers | docker ps -a |
| Live logs | docker logs -f --tail 100 web |
| Get a shell inside | docker exec -it web sh |
| Stop and remove | docker rm -f web |
Images and Dockerfile
| What | How |
|---|---|
| Build with a tag | docker build -t api:1.0.0 . |
| Without cache | docker build --no-cache -t api:1.0.0 . |
| Image layers | docker history api:1.0.0 |
| Copy files (not ADD) | COPY . . |
| Start command | CMD ["node", "server.js"] |
| No root | USER node |
Volumes and networks
| What | How |
|---|---|
| Named volume | -v pgdata:/var/lib/postgresql/data |
| Bind mount | -v "$(pwd)":/app |
| Network with DNS | docker network create app-net |
| Port on localhost only | -p 127.0.0.1:5432:5432 |
| Clean up unused | docker system prune |
Compose
| What | How |
|---|---|
| Build and run | docker compose up -d --build |
| Service state | docker compose ps |
| Service logs | docker compose logs -f web |
| Wait until ready | condition: service_healthy |
| Stop (volumes stay) | docker compose down |