Skip to content

Instantly share code, notes, and snippets.

@whomwah
Last active June 19, 2019 09:43
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 whomwah/e3780983238287ee41e1e58f8d92ad4c to your computer and use it in GitHub Desktop.
Save whomwah/e3780983238287ee41e1e58f8d92ad4c to your computer and use it in GitHub Desktop.
[Docker] useful commands #docker

Execute an interactive bash shell on the container

docker exec -it app-accounting bash

Remove unused volumes

$ docker volume rm (docker volume ls -q -f dangling=true)

Remove all images

$ docker rm (docker ps -a -q) | docker rmi (docker images -q)

Remove dangling images

$ docker rmi (docker images -q -f dangling=true)

Remove images with name set as NONE

$ docker rmi (docker images -a | grep "^<none>" | awk \'{print $3}\')

Shows how much space all your images, containers and volumes are using

$ docker system df

Reclaim some disk space

$ docker system prune

Basic command

$ docker run -i -t -rm kyan/rails:ruby2.4 /bin/bash # run a container and delete when closed

Deleting all the containers

Before deleting the volumes, you need to delete all the existing containers using the following command (make sure the application is not running)

$ docker rm $(docker ps -a -q) -f

Deleting all the volumes

Once all the containers are deleted, you can delete all the Docker volumes on your computer using the following command

$ docker volume prune

If you don't want to delete all the Docker volumes on your computer, you can search for a specific one and deleting it

$ docker volume ls
$ docker volume rm <name_of_volume>

Recreating the volumes

Recreating the volumes is as simple as restarting the application

$ docker-compose up --build

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