Skip to content

Instantly share code, notes, and snippets.

@skwid138
Last active November 1, 2022 19:08
Show Gist options
  • Save skwid138/5ee75cd45ce0a21cc9c6cb50f953bc1c to your computer and use it in GitHub Desktop.
Save skwid138/5ee75cd45ce0a21cc9c6cb50f953bc1c to your computer and use it in GitHub Desktop.

Helpful Commands

List containers

(The below are using the recomended commands although docker ps <options> would be identicle for now)

  • All containers: docker container ls -a
  • Running containers: docker container ls (docker ps is the exact same, but is no longer the recomended command)
  • All stopped containers: docker container ls -f "status=exited"
  • IDs of running containers: docker container ls -q
  • IDs of all containers: docker container ls -aq
  • Recently created containers: docker container ls -l

Stop and Kill Containers

  • Kill all containers: docker container kill $(docker container ls -q)
  • Kill specific container docker container kill <container name or ID>
  • Stop specific container docker container stop <container name or ID>
  • Stop all containers docker container stop $(docker container ls -q)

Remove containers

  • Remove one or more containers: docker container rm <container name(s) or container ID(s)>
  • Remove all containers docker container rm $(docker container ls -aq)

List Images

  • List all images docker image ls -a
  • IDs of all images docker image la -aq

Remove Images

  • Remove dangling images: docker image prune
  • Remove one or more images: docker image rm <image name(s) or ID(s)>
  • Remove all images: docker image rm $(docker image ls -aq)
@Namheelee
Copy link

Search by GitHub

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