Docker Cheat Sheet



Best Practices

Bash completion:

Bash completion needs the utility installed.  On OSX follow these steps: 

  1. http://stackoverflow.com/questions/26132451/how-to-add-bash-command-completion-for-docker-on-mac-os-x
  2. Do not skip the linked Stack Overflow on properly installing bash-completion using brew on OSX


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:

  1. Open VirtualBox
  2. Stop docker's virtual machine (likely named "default")
  3. Right click on virtual machine, go to Settings
  4. Go to Tab: System
  5. 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:

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




OpenLMIS: the global initiative for powerful LMIS software