📅  最后修改于: 2023-12-03 15:00:29.267000             🧑  作者: Mango
In Docker, a container can be removed using the docker rm
command. The command takes one or more container IDs or names as arguments and removes them from the Docker host.
To remove a running container, use the following command:
docker rm <CONTAINER_ID>
Where <CONTAINER_ID>
is the ID of the container you want to remove.
If the container is running, it must be stopped before it can be removed. You can stop a container using the docker stop
command:
docker stop <CONTAINER_ID>
Once the container has been stopped, you can remove it using the docker rm
command.
To remove multiple containers at once, you can specify their IDs or names separated by a space:
docker rm <CONTAINER_ID_1> <CONTAINER_ID_2> <CONTAINER_ID_3>
Alternatively, you can use the -f
flag to force the removal of all containers:
docker rm -f $(docker ps -aq)
This command uses the docker ps -aq
command to list all containers and pass their IDs to the docker rm
command for removal.
In summary, the docker rm
command is used to remove one or more containers from the Docker host. Remember to stop the container before removing it, and use the -f
flag to force the removal of multiple containers.