Menu Close

Docker – How to remove containers in docker

Here, we will help you to understand how to remove containers in docker. We use “docker rm container_name” command to remove container.

docker rmcommand can be used with various options to remove containers in docker.

Usage:

docker container rm [OPTIONS] CONTAINER [CONTAINER…]

Options:

NameDescription
--force , -fForce the removal of a running container (uses SIGKILL)
--link , -lRemove the specified link
--volumes , -vRemove anonymous volumes associated with the container

Example:

rootMac@ABCD ~ % docker ps

CONTAINER ID   IMAGE                    COMMAND                  CREATED          STATUS          PORTS                     NAMES

1486e1dfde13   redis:latest             "docker-entrypoint.s…"   30 seconds ago   Up 29 seconds   0.0.0.0:55000->6379/tcp   redis-AEJ4

9ffc5b61103b   docker/getting-started   "/docker-entrypoint.…"   37 seconds ago   Up 36 seconds   0.0.0.0:80->80/tcp        beautiful_mccarthy

Delete the redis container (Showing in the above docker ps command)

rootMac@ABCD ~ % docker stop redis-AEJ4
redis-AEJ4

rootMac@ABCD ~ % docker rm redis-AEJ4
redis-AEJ4

rootMac@ABCD ~ % docker ps

CONTAINER ID   IMAGE                    COMMAND                  CREATED         STATUS         PORTS                NAMES

9ffc5b61103b   docker/getting-started   "/docker-entrypoint.…"   3 minutes ago   Up 3 minutes   0.0.0.0:80->80/tcp   beautiful_mccarthy

>>>>> Here, redis container is not running.

*** Before deleting the container, Make sure It's in stopped state. You can't delete running container.

To learn more about golang, Please refer given below link:

https://www.techieindoor.com/go-lang-tutorial/

References:

https://en.wikipedia.org

Posted in docker

Leave a Reply

Your email address will not be published. Required fields are marked *