Cheat sheet · Systems and cloud
Docker cheat sheet
Build images, run and inspect containers, keep data, use Docker Compose and write a Dockerfile.
- Sections
- 6
- Items
- 31
- Area
- Systems and cloud
- Download
- PNG, PDF
Cheat sheet
Docker
Build images, run and inspect containers, keep data, use Docker Compose and write a Dockerfile.
Images
docker build -t myapp .- Build an image from the Dockerfile in this folder
docker images- List images
docker pull nginx- Download an image
docker rmi <image>- Delete an image
docker tag myapp user/myapp:1.0- Give an image another name
docker push user/myapp:1.0- Upload an image to a registry
Containers
docker run -d -p 8080:80 --name web nginx- Start in the background; open port 8080 on your machine
docker ps / docker ps -a- Running containers / all containers
docker stop web / docker start web- Stop / start again
docker rm web- Delete a stopped container
docker logs -f web- Follow the logs
docker exec -it web sh- Open a shell inside
docker run --rm -e KEY=value myapp- Run once, set a variable, then clean up
Data and networks
-v data:/var/lib/data- Keep a named volume so data survives the container
-v $(pwd):/app- Share the current folder (useful while developing)
docker volume ls- List volumes
docker network create app-net- Make a network so containers reach each other by name
Docker Compose
docker compose up -d- Start every service in docker-compose.yml
docker compose down- Stop and remove them
docker compose logs -f <service>- Follow one service's logs
docker compose ps- Status of the services
docker compose up -d --build- Rebuild images and start
Dockerfile
FROM node:22-slim- The base image
WORKDIR /app- The folder for the next commands
COPY package*.json ./- Copy files into the image
RUN npm ci- Run a command while building
ENV NODE_ENV=production- Set a variable
EXPOSE 3000- Document the port
CMD ["node", "server.js"]- The command that starts the container
Clean up
docker system prune- Remove stopped containers and unused data
docker image prune -a- Remove unused images
Remember
- Copy the package files and install first, then copy the rest. Docker caches the slow step.
- A container is one process with its own files. Keep data in volumes, not inside the container.
- Add a .dockerignore file so node_modules and .git do not go into the image.
Learn it properly
A cheat sheet helps you remember. These lessons explain the ideas step by step, with examples.