Skip to content

Instantly share code, notes, and snippets.

@hemanth22
Forked from elsauto/Docker-Commands.md
Created September 11, 2019 14:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hemanth22/4bc3fc2bfb69ec7843560f72d5ca4049 to your computer and use it in GitHub Desktop.
Save hemanth22/4bc3fc2bfb69ec7843560f72d5ca4049 to your computer and use it in GitHub Desktop.
Docker Commands #Docker #Docker-Compose

Docker Command Cheatsheet

Build our own image:

docker build -t my-image .

Delete All Exited Containers (Linux):

docker rm $(docker ps -q -f status=exited)

Delete All Exited Containers (Windows):

docker rm $(docker ps -aqf "status=exited")

On Windows 2016 Server Core: How to restart Docker Service?

Net stop com.docker.service
Net start com.docker.service

List:

$ docker ps -a | grep "pattern"

Remove:

$ docker images | grep "pattern" | awk '{print $1}' | xargs docker rm

Remove images with children (images). We should try to remove unnecessary images before removing the image itself:

docker rmi $(docker images -q -f dangling=true)
docker rmi $(sudo docker images --filter "dangling=true" -q --no-trunc)

Docker remove TAG images:

1. docker rmi $(docker images --filter "dangling=true" -q --no-trunc)
2. docker images -q -a | xargs docker inspect --format='{{.Id}}{{range $rt := .RepoTags}} {{$rt}} {{end}}'|grep -v ':'

Asmentioned for for docker 1.13+ in Sept. 2016 in "How to remove old and unused Docker images", we can also do the image prune command:

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