33 cards
`docker run -d -p 8080:80 --name web nginx:1.27`
run a container detached, map a port
`docker run -it ubuntu:22.04 bash`
run an interactive shell
`docker run --rm ubuntu:22.04 echo hello`
remove the container after it exits
`docker ps`
running containers
`docker ps -a`
all containers (including stopped ones)
`docker stop <name>`
graceful stop (SIGTERM → SIGKILL after 10s)
`docker kill <name>`
immediate stop (SIGKILL)
`docker start <name>`
start a stopped container
`docker restart <name>`
restart a container
`docker rm <name>`
remove a stopped container
`docker rm -f <name>`
force-remove a running container
`docker logs <name>`
view stdout/stderr
`docker logs -f <name>`
follow logs (tail -f)
`docker logs --tail 50 <name>`
last 50 lines
`docker exec -it <name> bash`
open a shell in a running container
`docker exec <name> <cmd>`
run a command in the container
`docker inspect <name>`
view detailed configuration (JSON)
`docker stats`
real-time CPU/RAM usage
`docker build -t myapp:1.0 .`
build an image from a Dockerfile
`docker build -f Dockerfile.prod -t myapp:prod .`
use a different Dockerfile
`docker images`
list images
`docker pull nginx:1.27`
pull an image from a registry
`docker push <registry>/<repo>:<tag>`
push an image to a registry
`docker tag myapp:1.0 myapp:latest`
create a new tag
`docker rmi myapp:1.0`
remove an image
`docker history myapp:1.0`
view the image's layers
`docker system prune -a`
remove all unused images, containers, and cache
`-p 8080:80`
map host port 8080 → container port 80
`-v /host/path:/container/path`
bind mount
`-v myvolume:/container/path`
named volume
`-v /host/path:/container/path:ro`
read-only mount
`-e KEY=value`
set an env var
`--env-file .env`
load from a file