Skip to content

Instantly share code, notes, and snippets.

@zganger
Last active January 8, 2023 15:12
Show Gist options
  • Save zganger/b88b2ace798aadf05c14d4978cf7f1f7 to your computer and use it in GitHub Desktop.
Save zganger/b88b2ace798aadf05c14d4978cf7f1f7 to your computer and use it in GitHub Desktop.
Helpful Docker CLI commands (1.13.x+ syntax)

Some helpful commands for Docker CLI

With release 1.13, Docker has greatly simplified interacting with the various assets docker containers use to run. These components include containers, networks, volumes, and images.

  • List all images: docker image ls -a

  • List all containers: docker container ls -a

  • Stop all containers: docker container stop $(docker container ls -aq)

  • Remove all stopped containers: docker container rm -v $(docker container ls -aq)

  • Pull new images: docker pull <container>:<version> (default version is :latest)

  • Remove dangling images (do this after pulling new versions, so that you keep your images clean): docker image rm $(docker image ls -f "dangling=true" -q)

  • To clean up your system completely (remove all orphaned containers, networks, volumes): docker system prune

  • To ssh into container: docker exec -it /bin/bash

Summary:

To use docker CLI, select an asset from container, image, volume, or network, then a command to execute, then the ID or list of IDs of the assets you would like to interact with. Syntax is of form: docker <asset> <command> <id> <options>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment