Open In App

What Is Docker rm Command ?

Last Updated : 15 Mar, 2024
Improve
Improve
Like Article
Like
Save
Share
Report

“docker rm” is used to remove one or more Docker containers that are running on the Docker host. A Docker container uses up system resources like CPU, memory, and disk space when it is running. To free up such resources, you may choose to uninstall a container after using it for a while.

docker rm [OPTIONS] CONTAINER [CONTAINER…]

  • OPTIONS: Various options can be used with the docker rm command to modify its behavior.
  • CONTAINER: The name or ID of the Docker container(s) to be removed.

Step-By-Step Process To Remove Docker Container

Step 1: Provide a list of every container on the Docker host.

docker ps -a 

Step 2: Stop the docker container before deleting it.

docker stop <Container name> or <Contaier ID>

Step 3: Remove the Docker container when it has stopped; you cannot remove the Docker container unless it has stopped.

docker rm <Container name> or <Contaier ID>

docker rm

Removing Multiple Docker Containers

You may easily remove a multi-container in Docker by using the following command.

docker rm container1 container2 container3
  • docker rm: This is the Docker command for removing containers.
  • container1 container2 container3: These are the names or IDs of the Docker containers

docker rm multi container

Force Remove Docker Container

Even when a container is in operation, it can be forcefully removed by using the -f or –force option with the docker rm command. If you wish to forcefully remove a running container, you must use the -f option since Docker does not enable this by default.

docker rm -f CONTAINER_ID_or_NAME

You can see that I attempted to remove the Docker container both with and without the -f option in the following image.

Docker rm -f

Remove All Stopped And Running Containers At Once

Remove All Stopped Containers

To unstop every container at once, use the following command.

docker rm $(docker ps -aq)
  • docker ps -aq: This command lists all Docker container IDs in a quiet mode, which means it only outputs the container IDs without any additional information. Here’s what each part does:
  • docker ps: Lists all Docker containers.
  • -a or –all: Shows all containers, including stopped ones.
  • -q or –quiet: Outputs only container IDs.
  • $(…): This is command substitution in Bash. The output of the command inside the parentheses is substituted and executed in the outer command.
  • docker rm: This command removes Docker containers.

Remove All running Containers

Add the -f argument to the command above.

docker rm -f $(docker ps -aq)

docker rm all the contaienrs

People Also Read

Docker

Docker Commands

Read

Dockerfile

Read

Docker Tutorials

Read

Conclusion

To sum up, the docker rm command is an effective tool for eliminating Docker containers from your computer. It enables you to remove containers that are no longer required, freeing up system resources. The name or ID of the container(s) you wish to delete should be specified in the command’s basic format, docker rm [OPTIONS] CONTAINER [CONTAINER…]. The -f or –force option allows you to force the removal of running containers, however by default the operation simply removes halted containers. Furthermore, you can eliminate multiple containers, filter containers according to particular standards, or eliminate containers in bulk by combining different commands and parameters. Use caution at all times while executing the docker rm command, especially when the -f option is present, to prevent unexpected.

Docker rm Command – FAQ’s

How do I delete a file in docker?

To delete a file within a Docker container, you typically use the docker exec command to execute a shell command inside the container.

docker exec CONTAINER rm /path/to/example.txt

What is the command for RM images docker?

The command for removing Docker images is docker rmi. Here’s the basic syntax:

docker rmi [OPTIONS] IMAGE [IMAGE...]


Similar Reads

Docker - Docker Container for Node.js
Node.js is an open-source, asynchronous event-driven javascript runtime that is used to run javascript applications. It is widely used for traditional websites and as API servers. At the same time, a docker container is an isolated, deployable unit that packages an application along with its dependencies, making it highly scalable and maintainable.
7 min read
Docker - Using Public Repositories To Host Docker Images
Pre-requisites: DockerDocker is a software platform for creating isolated virtualized environments for building, deploying, and testing applications with ease. In this tutorial, we will learn how to host public repositories on docker hub which is a hosted repository service provided by Docker for finding and sharing container images. Just like GitH
3 min read
How to Use Docker For Fault Tolerance with Docker Replicas?
Docker is a set of platform-as-a-service products that use OS-level virtualization to deliver software in packages called containers. A cluster of docker engines is called a swarm. Docker Swarm is a cluster management and orchestration feature embedded in the Docker Engine. Docker ReplicasDocker replicas refer to running multiple instances of a doc
4 min read
How to Use Docker For Cross-Platform Containerization with Docker Buildx?
Docker has completely modified the manner in which software program is evolved and deployed, with the aid of introducing containerization generation. In order to package programs with their dependencies and make certain consistency of conduct across many contexts, packing containers offer a compact and portable solution. Deploying containerized app
7 min read
How to Use Docker Content Trust to Verify Docker Container Images
The world of containerized applications is based on trust. You rely on Docker images to be exactly what they say they are: secure, reliable, robust, and built with the right elements. But just like you can not just blindly trust any random ingredient in your kitchen, similarly the Docker image needs a kind of verification so we don't need to be con
12 min read
Docker Compose vs Docker Swarm
Docker is one of the most widely used container-based software on the market. Docker is an open-source platform for creating, deploying, and managing containerized applications. Docker allows us to simply bundle our apps into containers and can be deployable on any platform that supports docker software acting as a platform independent. What Is Doc
6 min read
Docker CLI vs Docker Desktop
Docker is an open-source platform. It is used to containerize applications. This is done by packaging applications along with their dependencies into containers that can be easily deployed. Users interact with Docker primarily using either the Docker CLI or the Docker Desktop Application. In this article, we'll be looking into each one in detail an
5 min read
Docker: How To Use Bash With An Alpine Based Docker Image?
Docker is a tool that is used to encapsulate the application with all its dependencies, called Docker containers. On the other hand, Alpine Linux is a lightweight and minimal Linux distribution. Here in this guide, I will first discuss what Docker is. Then I will discuss what Alpine is. After this, I will walk you through the different steps to ins
5 min read
Docker - Deploying WebApps on Docker
Docker applies abstraction at the software layer of the operating system to create an instant and portable environment that includes everything you need: a Linux kernel, libraries, system tools like grep or sshfs, plus applications (web servers/services) and all dependencies needed by those applications (e.g., database engines). When deployed, thes
9 min read
How To Use Docker Desktop To Deploy Docker Containerized Applications
Docker Desktop is a versatile and user-friendly tool that simplifies the deployment of Docker containerized applications on your local machine. It provides a graphical interface for managing containers, images, and volumes, making it accessible for developers and DevOps professionals. In this guide, we will walk you through the essential steps of u
7 min read
Article Tags :