Part2 - Docker Commands with Examples

2 Likes
over 1 year ago

This is an extension of the cool solution I posted earlier.

Let us go through some more docker commands.

1. docker rm <container id>

Use this command to delete a stopped container.

docker-rm-help.PNG

 

Example:  docker rm 460b4bacfb94

In the above command "460b4bacfb94" is the container ID. You need to run the "docker ps" command to see the container ID.

 Flags:

-a, show all 

-q, show only numeric IDs

We can use the above flags with both containers and images.

2. docker kill $(docker ps -q)

Use this command to stop all the containers.

3. docker rm $(docker ps -a -q)

Use this command to remove all the containers.

Alternate command

docker rm `docker ps --all`

4. docker rm --force `docker ps --all`

Use this command to remove all containers in any state.

5. docker rmi <image-id>

Use this command to delete an image from local storage.

docker-rmi-help.PNG

 

6. docker rmi $(docker images -q)

Use this command to remove all docker images.

7. docker volume prune

Use this command to purge the volume used by dockers.

Note: The volumes exist independently from containers so when a container is removed, a volume is not automatically removed at the same time.

Please be careful with the below command

8. docker system prune

Use this command to purge all unused images, containers, volumes, and networks.

Labels:

Education-Training
Other
Comment List
Anonymous
Related Discussions
Recommended