Docker Command Cheat Sheet
Docker Command Cheat Sheet Note: All commands need to be run with sudo Click here for sample template data List running containers
$ sudo docker ps List available images
$ sudo docker images Run a container
Note: Docker containers automatically die when they complete their last task, so if you run docker with, for example, /sbin/service httpd start, when the service command ends and Exits 0, the container dies. You can get around this by passing it “/bin/bash” and running it interactively, as the shell will keep the container alive. However, if you attach to the container, and then use exit or Ctl-D to disconnect, then the container will die. You must use a special key command, Ctl-p Ctl-q, to detach. Think of it like a screen session. $ sudo docker run -p [[host_port]]:[[container_port]] -v [[host_dir]]:[[container_dir]] -d -i -t [[image_name]] [[command]] -p [[host_port]]:[[container_port]] Maps a network port on the host server to a port on the container -v [[host_dir]]:[[container_dir]] Creates a bind mount (shares the host filesystem with the container) -d Run as daemon (runs in background) -i -t Run interactively (it does more stuff, but that’s what this boils down to) [[image_name]] The image from which to create the container [[command]] Command to pass to the container Connect to a running container
Note: must be interactive and have a shell to be of use $ sudo docker attach --sig-proxy=true [[container_name]] $ sudo docker attach --sig-proxy=true [[container_id]] –sig-proxy=true Proxify all received signal to the process (even in non-tty mode) Remove all images
WARNING: be careful! $ docker images -a -q | xargs docker rmi Remove Stopped Containers
$ docker ps -a | awk '/Exit/ {print $1}' | xargs docker rm Remove all containers (including running containers)
$ docker ps -q -a | xargs docker rm Source: http://sites.duke.edu/docker/docker-command-cheat-sheet/



host_port:
container_port:
host_dir:
container_dir:
image_name:
command:
container_name:
container_id:


Use this code to post the full script to your own page:



Use this code to post only the variables to your own page: