Skip to content

Instantly share code, notes, and snippets.

@Adron

Adron/docker-commands.sh

Last active Apr 26, 2021
Embed
What would you like to do?
Docker Commands : Killing/Stopping/Removing Containers and Images
# Stopping a single container that is running.
docker stop 0bd1f4ccb52d
# Stopping two or more containers that are running.
docker stop 0bd1f4ccb52d 0bd1f4ccb52d
# Showing a list of all containers.
docker ps -a
# Showing a list of the container IDs that are actively running.
docker ps -q
# Showing a list of the container IDs for those that are stopped and actively running.
docker ps -aq
# Stopping all the containers returned from the list of IDs, which in this case is all of the actively running containers.
docker stop $(docker ps -q)
# Cleanup the volumes that any the database or related images/containers may have left behind.
docker volune prune
# Removing the containers that are actively running and stopped.
docker rm $(docker ps -aq)
# Removing all of the container images by their respective ID.
docker rmi $(docker images -q)
# Tweak to force remove all images.
docker rmi $(docker images -q) -f
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment