Skip to content
lanzai.co
Go back

Docker Commands Cheat Sheet

High-frequency Docker commands, organized by scenario.

Images

docker images                    # list images
docker pull nginx:alpine         # pull an image
docker rmi nginx:alpine          # remove an image
docker build -t myapp .          # build an image
docker tag myapp myapp:v1        # tag an image
docker push myuser/myapp:v1      # push an image

Containers

docker run -d --name web -p 8080:80 nginx        # run detached with port mapping
docker ps                                        # running containers
docker ps -a                                     # all containers
docker start|stop|restart web                    # start/stop/restart
docker rm -f web                                 # force remove
docker exec -it web /bin/sh                      # shell into a container
docker cp web:/etc/nginx/nginx.conf ./           # copy files
docker logs -f web                               # follow logs
docker inspect web                               # container metadata

Cleanup

docker system df                  # check disk usage
docker system prune               # clean dangling resources
docker system prune -a --volumes  # full cleanup
docker image prune -a             # remove unused images

Compose

docker compose up -d              # start services
docker compose down               # stop and remove
docker compose ps                 # status
docker compose logs -f            # logs
docker compose exec app sh        # shell into a service
docker compose pull               # update images

Networks and volumes

docker network ls
docker volume ls
docker run --network host ...

Resource limits

docker run -d --memory 512m --cpus 1 nginx

Share this post:

Previous Post
Installing Docker Compose and Common Commands
Next Post
Installing Nginx and Basic Configuration