Docker stop Stop and remove Delete All Containers

  • 2021-09-25 00:09:28
  • OfStack

This article mainly introduces Docker stop stop/remove delete all containers, and shares them with you as follows:


$ docker ps //  View all running containers 
$ docker stop containerId // containerId  Is the container's ID

$ docker ps -a //  View all containers 
$ docker ps -a -q //  View all containers ID

$ docker stop $(docker ps -a -q) // stop Stop all containers 
$ docker rm $(docker ps -a -q) // remove Delete all containers 

Common commands for Docker:

[Ctrl + C]: Exiting does not end the current container process,

Help commands:


docker --help

View version


docker --version

View all images


docker images

Delete a container


docker rm [NAME]/[CONTAINER ID]

Unable to delete 1 running container, error will be reported. You need to stop the container first

View all containers


docker ps

docker images

List all local mirrors


docker search <IMAGE_ID/NAME>

: Find image


docker pull <IMAGE_ID> 

Download image


docker push <IMAGE_ID>

Upload image


docker --help
0

: Delete image

Container management
docker run -i -t < IMAGE_ID > /bin/bash:-i: Standard input to container-t: Assign 1 virtual terminal/bin/bash: Execute bash script
-d: Run as a daemon (background)
-P: Default matches port number 5000 of the docker container to port 49153 to 65535 of the host machine
-p < HOT_PORT > : < CONTAINER_PORT > : Specify port number

-name: Specifies the name of the container -rm: Delete container on exit

docker stop < CONTAINER_ID > Stop container
docker start < CONTAINER_ID > : Restart container
docker ps - Lists containers.

-l: Displays the last started container -a: Displays the stopped container at the same time, and only displays the startup status by default

docker attach < CONTAINER_ID > Connect to Started Container
docker logs < CONTAINER_ID > Output container log

-f: Real-time output

docker cp < CONTAINER_ID > : path hostpath: Copy the files in the container to the host directory
docker rm < CONTAINER_ID > : Delete container
docker rm docker ps-a-q: Remove all containers
docker kill docker ps -q
docker rmi docker images -q -a
docker wait < CONTAINER_ID > Blocks other invocation methods on the container until the container stops and exits

docker top < CONTAINER_ID > View the processes running in the container
docker diff < CONTAINER_ID > : View changes in containers
docker inspect < CONTAINER_ID > : View container details (output is Json)

-f: Find specific information such as docker inspect-f '{{. NetworkSettings. IPAddress}}'

docker commit-m "comment"-a "author" < CONTAINER_ID > ouruser/imagename:tag

docker extc -it < CONTAINER > < COMMAND > Execute a command in a container and output the result


Related articles: