Docker Cheat Sheet
Best Practices
- See the service style guide
Bash completion:
Bash completion needs the utility installed. On OSX follow these steps:
- http://stackoverflow.com/questions/26132451/how-to-add-bash-command-completion-for-docker-on-mac-os-x
- Do not skip the linked Stack Overflow on properly installing bash-completion using brew on OSX
- Compose: https://docs.docker.com/compose/completion/
- Docker (on OSX): http://stackoverflow.com/questions/26132451/how-to-add-bash-command-completion-for-docker-on-mac-os-x
Running without root (not using sudo)
Docker runs as root on a host machine. With most Linux installs, you'll need to give your user account access to docker so that you don't need to run every Docker command with sudo.
http://askubuntu.com/questions/477551/how-can-i-use-docker-without-sudo
Performance
In OS X (and likely Windows), using Docker Machine is essentially using VirtualBox. The default virtual machine you created through Docker Machine likely was created to use one CPU, set memory etc. It can be very useful to increase these virtual machine limits. The general steps are:
- Open VirtualBox
- Stop docker's virtual machine (likely named "default")
- Right click on virtual machine, go to Settings
- Go to Tab: System
- Adjust memory size and CPU on Motherboard and Processor tabs respectively.
Docker on Windows
Set up Docker environment in command prompt or Powershell (instead of using Quickstart shell)
docker-machine env
Helpful scripts:
- Josh's bash on OSX (source in ~/.bash_profile): https://github.com/joshzamor/scripts/blob/master/dockercheatsheet.sh
Cleaning up:
Docker recently added a docker system prune command which can be used for thorough and convenient cleanup. Environments which don't yet sport the command, however, offer the following alternatives.
Remove unused volumes (do not run on <= 1.9):
docker volume rm $(docker volume ls -qf dangling=true)
Remove unused images:
docker images | grep "<none>" | awk '{print $3}' | xargs docker rmi
Remove all exited containers:
docker rm `docker ps -a | grep Exit | awk '{ print $1 }'`
or
docker stop $(docker ps -a -q) docker rm $(docker ps -a -q)
- Attempt to remove all networks:
docker network rm $(docker network ls --format {{.ID}})
View running containers:
This shows a real-time list of containers by ID with their CPU and Memory usage:
docker stats
More Resources
- JRebel cheat sheat: http://zeroturnaround.com/rebellabs/docker-commands-and-best-practices-cheat-sheet/
OpenLMIS: the global initiative for powerful LMIS software