Docker

Build images, run containers and manage Compose stacks, volumes and networks.

Containers #compose#containers#devops#docker Last updated
Library

Images#

docker build -t myapp:1.0 .            # build from ./Dockerfile
docker build --no-cache -t myapp .     # rebuild every layer
docker images                          # list local images
docker pull nginx:1.27-alpine          # download an image
docker rmi myapp:1.0                   # remove an image
docker image prune -a                  # remove all unused images

Containers#

docker run -d --name web -p 8080:80 nginx:1.27-alpine
docker run --rm -it alpine:3.20 sh     # throwaway interactive container
docker ps -a                           # list all containers
docker logs -f --tail 100 web          # follow logs
docker exec -it web sh                 # shell inside a running container
docker stop web && docker rm web

Useful docker run flags#

Flag Meaning
-d Run in the background
-p 8080:80 Publish host port 8080 to container port 80
-v data:/var/lib/app Mount the named volume data
-e KEY=value Set an environment variable
--env-file .env Load environment variables from a file
--read-only Read-only root filesystem
--restart unless-stopped Restart policy

Docker Compose#

docker compose up -d --build     # build and start in the background
docker compose ps                # service status (incl. health)
docker compose logs -f app       # follow one service's logs
docker compose exec app sh       # shell in a running service
docker compose down              # stop and remove containers (keeps volumes)
docker compose down -v           # also delete named volumes (data loss!)

Volumes and networks#

docker volume ls
docker volume inspect myvolume
docker network ls
docker network create backend

Clean up#

docker system df          # disk usage
docker system prune       # remove stopped containers, unused networks, dangling images

Back to library

Keyboard shortcuts

/
Focus search
Esc
Close dialogs, menus and messages
?
Show this help
Ctrl S
Save in the admin editor