This Blog is to share our knowledge and expertise on Linux System Administration and VMware Administration

Monday, January 15, 2018

Working with Docker Container - Deleting a container

Deleting a container

We can delete a container permanently, but before that we have to stop the container or use the force option. In this recipe, we'll start, stop, and delete a container.
Syntax : docker rm [ OPTIONS ] CONTAINER [ CONTAINER ]

Let's first start a container, stop it, and then delete it using the following commands:

root@Docker:~# id=`docker run -d -i centos /bin/bash`
root@Docker:~# docker stop $id
e62286794466459f2dd08d5f1cec0749187247ffabb5224d6b6b3aae334d4bf8
root@Docker:~# docker rm $id
e62286794466459f2dd08d5f1cec0749187247ffabb5224d6b6b3aae334d4bf8

To forcefully delete a container without an intermediate stop, use the -f option.

To delete all the containers, we first need to stop all the running containers and then remove them. Be careful before running the commands as these will delete both the running and the stopped containers:

root@Docker:~# docker stop `docker ps -q`
root@Docker:~# docker rm `docker ps -q`

For help with the docker rm use --help

No comments:

Post a Comment