Cheat Sheet
Basics
- docker command line structure
docker command sub-command (options)
- use --help after any of the command below to get help on syntax and available subcommands or options
Old vs new commands
- Lot of commands are moving under specific resource commands
- E.g. docker ls is now available in docker container or docker image, etc.
Info
docker version # shows information about client and server
docker info # show config values
Containers
Manage Containers
docker container ls # list active containers
docker container ls -a # list all containers, including those that are inactive
docker rm <id> <id> <id> # removes inactive containers
docker rm -f <id> <id> # removes any containers
docker update # update configuration of one or more containers
Various information
docker container top # process list in one container
docker container inspect # returns JSON metadata about the container
docker container stats # performance stats for all containers
docker container port # show which ports are open for a container
Shell and Execute
docker container run -it # start new container interactively
docker container start -ai # start existing container interactively
docker container exec -it # run additional command in existing container
Format
docker container inspect --format '{{ .NetworkSettings.IPAddress }}'
Networking
docker network ls # list networks
docker network inspect # returns JSON metadata about the network
docker network create # create a network
docker network connect # attach a network to container
docker network disconnect # detach a network from container
docker network rm # remove one or more networks
docker network prune # remove all unused networks
Images
docker image ls # list local/cached images
docker image build # build an image from a Dockerfile
docker image history # show layers of changes made in image
docker image inspect # returns JSON metadata about the image
docker image tag # re-tag existing image [defaults to latest]
docker image pull # download image from registry
docker image push # uploads changed layers to a image registry
docker image build # builds image from Dockerfile
docker image prune # remove all unused images
Volumes
docker volume ls # list volumes
docker volume inspect # returns JSON metadata about the image
docker volume create # create a volume
docker volume rm # removes a volume
docker volume prune # remove all unused volumes
Swarm
docker swarm ca # display and rotate the root CA
docker swarm init # enable docker swarm mode
docker swarm join # join a swarm as a node and/or manager
docker swarm join-token # manage join tokens
docker swarm leave # leave the swarm
docker swarm update # update the swarm
docker swarm unlock # unlock swarm
docker swarm unlock-key # manage the unlock key
Nodes
docker node ls # list nodes in the swarm
docker node ps # list tasks running on one or more nodes
docker node inspect # returns JSON metadata about one or more nodes
docker node update # update a node
docker node promote # promote one or more nodes to manager
docker node demote # demote one or more nodes from manager
docker node rm # remove one or more nodes from the swarm
Services
docker service create # create a new service
docker service inspect # returns JSON metadata about one or more services
docker service logs # fetch the logs of a service or task
docker service ls # list services
docker service ps # list the tasks of one or more services
docker service rm # remove one or more services
docker service rollback # revert changes to a service's configuration
docker service scale # scale one or multiple replicated services
docker service update # update a service
Stacks
docker stack deploy # Deploy a new stack or update an existing one
docker stack ls # List stacks
docker stack ps # List the tasks in the stack
docker stack rm # Remove one or more stacks
docker stack services # List the services in the stack
Secrets
docker secret create # Create a secret from a file or STDIN as content
docker secret inspect # returns JSON metadata about one or more secrets
docker secret ls # List secrets
docker secret rm # Remove one or more secrets
Docker Compose CLI
docker-compose up # setup volumes/networks and start all containers
docker-compose up -d # daemonize it
docker-compose down # stop all containers and remove cont/vol/net/img
docker-compose logs [-f] # show logs [-f will keep it open]
docker-compose build # build or rebuild services
docker-compose bundle # generate a Docker bundle from the Compose file
docker-compose config # validate and view the Compose file
docker-compose create # create services
docker-compose events # receive real time events from containers
docker-compose exec # execute a command in a running container
docker-compose help # get help on a command
docker-compose images # list images
docker-compose kill # kill containers
docker-compose pause # pause services
docker-compose port # print the public port for a port binding
docker-compose ps # list containers
docker-compose pull # pull service images
docker-compose push # push service images
docker-compose restart # restart services
docker-compose rm # remove stopped containers
docker-compose run # run a one-off command
docker-compose scale # set number of containers for a service
docker-compose start # start services
docker-compose stop # stop services
docker-compose top # display the running processes
docker-compose unpause # unpause services
docker-compose version # show the Docker-Compose version information
Docker Machine CLI
docker-machine active # print which machine is active
docker-machine config # print the connection config for machine
docker-machine create # create a machine
docker-machine env # display the commands to set up the environment for the Docker client
docker-machine inspect # returns JSON metadata about a machine
docker-machine ip # get the IP address of a machine
docker-machine kill # kill a machine
docker-machine ls # list machines
docker-machine provision # re-provision existing machines
docker-machine restart # restart a machine
docker-machine rm # remove a machine
docker-machine ssh # log into or run a command on a machine with SSH.
docker-machine scp # copy files between machines
docker-machine start # start a machine
docker-machine status # get the status of a machine
docker-machine stop # stop a machine
docker-machine upgrade # upgrade a machine to the latest version of Docker
docker-machine url # get the URL of a machine
docker-machine version # show the Docker Machine version or a machine docker version