Skip to content

Instantly share code, notes, and snippets.

@daniloab
Last active June 23, 2023 22:14
Show Gist options
  • Save daniloab/dbea32701e323975bf2d4d51a48f33b5 to your computer and use it in GitHub Desktop.
Save daniloab/dbea32701e323975bf2d4d51a48f33b5 to your computer and use it in GitHub Desktop.

filter

volume

  • docker ps --filter volume=VOLUME_NAME

list

container doc

  • docker container ls

    • flags: -a: all containers
  • all status exited docker ps --filter "status=exited

image

  • docker image ls

remove

  • all containers docker container rm $(docker container ls -aq)
  • all images docker image rm $(docker image ls -aq)
  • all volumes docker volume rm $(docker volume ls -q)
  • docker rm CONTAINER_NAME: delete the container to free disk space
  • docker rmi IMAGE_NAME:TAG: remove image from your computer to free disk space

run

  • docker run -d -p 27017:27017 -v data:/data/db mongo -d: development -v: version

start/stop

  • docker start CONTAINER_NAME
  • docker stop CONTAINER_NAME
  • stop all docker container stop $(docker container ls -aq)

more commands

  • kill all running containers with docker kill $(docker ps -q)
  • delete all stopped containers with docker rm $(docker ps -a -q)
  • delete all images with docker rmi $(docker images -q)
  • date and stop a container that is in a crash-loop with docker update --restart=no && docker stop
  • sh shell into container docker exec -i -t /bin/bash - if bash is not available use /bin/sh
  • sh shell with root if container is running in a different user context docker exec -i -t -u root /bin/bash
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment