Docker Cheat Sheet

That’s my personal cheat sheet for using Docker.


  • Data directory of my Docker services is /var/docker/. It’s also root directory for all following commands
  • I’m using service as a generic term for image and container
  • doco is an abbreviation for docker-compose (see installation guide below)
  • I’m using Git for versioning of Dockerfiles

Basic commands

Show status of containers

docker ps -a

Start services

doco up -d

Stop services

doco down

Remove container

docker rm <container:tag> [<container:tag> ...]

Show images

docker images

Remove image

docker rmi <image:tag> [<image:tag> ...]

Connect to shell in running container

docker exec -it <container> bash

Show Docker’s disk usage

du -hs /var/lib/docker/ /var/docker/

Versioning commands

Synchronize local and central repository

  • Fetch from central repository and merge automatically
    • git pull
  • Fetch and review changes before merging
    • git fetch and show differences with git log HEAD..origin
  • Push changes from local to central repository
    • git push

Show versioning status

git status

Add files to version control

  • Add files to index
    • git add .
  • Add files to repository
    • git commit -am "<message>"

Advanced commands

Backup and restore

For simple temporary backups you can use tar archives.

Create backup

  • Full backup
    • tar -czf backups/Full_$(date +%Y-%m-%d_%H-%M-%S).tar.gz docker-compose.yml services/
  • Partial backup (example)
    • tar -czf backups/<service>_$(date +%Y-%m-%d_%H-%M-%S).tar.gz services/<service>/data/

Restore backup

  • Complete restore
    • tar -xzf backups/Full_YYYY-MM-DD_HH-MM-SS.tar.gz
  • Partial restore of full backup (example)
    • tar -xzf backups/Full_YYYY-MM-DD_HH-MM-SS.tar.gz services/<service>/data/


Setting up Docker on Ubuntu