Skip to content

Instantly share code, notes, and snippets.

@VishalTaj
Last active August 7, 2022 13:00
Show Gist options
  • Save VishalTaj/53570ad1e09e7e3a81364e3590d6a475 to your computer and use it in GitHub Desktop.
Save VishalTaj/53570ad1e09e7e3a81364e3590d6a475 to your computer and use it in GitHub Desktop.
quick reference

Delete all images using the following command:

docker rmi $(docker images -a -q)

Delete all containers using the following command:

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

Delete all volumes using the following command:

docker volume rm $(docker volume ls -q)

Clean Up Docker Files

Will remove all unused volume and images

docker image prune -a
docker volume prune

Remove all containers that aren't running.

docker rm -vf $(docker ps -a -q --filter "status=exited")

Remove untagged images.

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

Remove unused volumes using "rm" or "prune".

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

Remove unused networks.

docker network prune -f

The sections below give a brief overview of identifying and removing objects, as well as links to the documentation for each command.

Containers

The docker ps command allows you to identify existing containers.

Display running containers.

docker ps

Display all containers using "-a" or "--all".

docker ps -a
docker ps --all

Filter output using "-f" or "--filter".

docker ps -f "status=exited"
docker ps --filter "status=exited"

Show only the container ID using "-q" or "--quiet".

docker ps -q -f "status=exited"
docker ps --quiet --filter "status=exited"

Containers are removed using the docker rm command.

Remove an individual container by ID or name. Use "-v" or "--volumes" to remove associated volumes. Use "-f" or "--force" to remove running containers.

docker rm -vf b0479f9d1ea4
docker rm --volumes --force ol7_ords_con

Remove all the containers matching the "ps" output.

docker rm -vf $(docker ps -a -q --filter "status=exited")

Images

Images are displayed using the docker images command.

Show top-level images only.

docker images

Show all images using "-a" or "--all".

docker images -a
docker images --all

Filter the output using "-f" or "--filter".

docker images -f "dangling=true"
docker images --filter "dangling=true"

Display only the image ID using "-q" or "--quiet".

docker images -q -f "dangling=true"
docker images --quiet --filter "dangling=true"

Images are removed using the docker rmi command.

Remove image by image ID or repository:tag

docker rmi ffcd22192b23
docker rmi ol7_122:latest

Force the remove using "-f" or "--force".

docker rmi -f ffcd22192b23
docker rmi --force ol7_122:latest

Remove images matching list.

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

Volumes

Docker volumes are listed using the docker volume ls command.

List all volumes.

docker volume ls

Filter output using "-f" or "--filter".

docker volume ls -f "dangling=true"
docker volume ls --filter "driver=local"

Display only volume name using "-q" or "--quiet".

docker volume ls -q -f "driver=local"
docker volume ls --quiet --filter "driver=local"

Volumes are removed using the docker volume rm command.

Remove specified volume.

docker volume rm test_vol

Force removal using "-f" or "--force".

docker volume rm -f test_vol
docker volume rm --force test_vol

Remove unused volumes.

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

You can also use the docker volume prune command.

Remove unused volumes.

docker volume prune -f

Networks

Networks don't waste any disk space, but you might want to clean up unused networks anyway.

Networks are listed using the docker network ls command.

List all networks.

docker network ls

Filter output using "-f" or "--filter".

docker network ls -f "driver=bridge"
docker network ls --filter "driver=bridge"

Display only network ID using "-q" or "--quiet".

docker network ls -q -f "driver=bridge"
docker network ls --quiet --filter "driver=bridge"

Networks are removed using the docker network rm command.

Remove network by name or ID.

docker network rm my_network2
docker network rm 6466079abd47

Alternatively, you can remove unused networks using the docker network prune command.

Remove unused networks.

docker network prune

Force prune using "-f" or "--force".

docker network prune -f
docker network prune --force

clear restricted file

sudo truncate -s0 access.log

puma restart

RAILS_ENV=production bundle exec puma -C /path/to/puma/file/inside/project/puma.rb --daemon

update wp user password from codebase

echo wp_set_password('your-password', 1);

get the size

du -hf
df -h

find 5 largest consumed file

du -a | sort -n -r | head -n 5

check cloud sql proxy

netstat -tulpn

cat /etc/cloudsql/cloudsql.conf

get the running vms in Virtualbox

VboxManage list runningvms

remove all prune Resque Workers

Resque.workers.first.prune_dead_workers

Postgres reset index

PG::UniqueViolation: ERROR: duplicate key value violates unique constraint

ActiveRecord::Base.connection.reset_pk_sequence!('moderations')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment