docker remove container and image code example

Example 1: remove docker container

# List all containers (only IDs)
docker ps -aq
# Stop all running containers
docker stop $(docker ps -aq)
# Remove all containers
docker rm $(docker ps -aq)
# Remove all images
docker rmi $(docker images -q)

Example 2: docker remove all containers and images

docker container rm $(docker container ls -aq)

Example 3: remove docker image

docker image rm [image id]

Example 4: docker remove all containers and images

docker container stop $(docker container ls -aq)

Example 5: docker remove dangling images

docker image prune

Example 6: remove docker images

docker system prune -a

Tags:

C Example