Article Directory
Docker kill command
Overview of the Docker kill command
The docker kill command can be used to kill one or more running Docker containers . The CONTAINER after this command can be the container ID or the container name.
Docker kill command syntax
haicoder(www.haicoder.net)# docker kill [OPTIONS] CONTAINER [CONTAINER...]
Docker kill command parameters
parameter | illustrate |
---|---|
-s | Send a signal to the container. |
the case
Kill the container using the container ID
First, use the docker run command to create and run a docker container.
haicoder(www.haicoder.net)# docker run -d -it --name haicoder ubuntu
59f80afcdd52626ad360af97d17b472193eb9b5cada56efa0147d6b78acdaa1d
Use the docker ps command to view the currently running containers, as shown in the following figure:
Now we use the docker kill command to kill the docker container that was just running.
haicoder(www.haicoder.net)# docker kill 59f80afcdd52
59f80afcdd52
Use the docker ps command again to view the currently running containers, as shown in the following figure:
At this point, we found that there were no running Docker containers, that is, the container was killed. That is, in the above case, we use the docker kill containerId command to kill a running docker container.
Finally, we use the docker rm command to remove all docker containers.
haicoder(www.haicoder.net)# docker rm $(docker ps -aq)
59f80afcdd52
Kill a container using its name
First, use the docker run command to create and run a docker container.
haicoder(www.haicoder.net)# docker run -d -it --name haicoder ubuntu
f725c5d8814be0ab4645bcb40e17190338ecb2707e581e24c38f57d0646211f3
Use the docker ps command to view the currently running containers, as shown in the following figure:
Now we use the docker kill command to kill the docker container that was just running.
haicoder(www.haicoder.net)# docker kill haicoder
haicoder
Use the docker ps command again to view the currently running containers, as shown in the following figure:
At this point, we found that there were no running Docker containers, that is, the container was killed. That is, in the above case, we use the docker kill containerName command to kill a running docker container.
Finally, we use the docker rm command to remove all docker containers.
haicoder(www.haicoder.net)# docker rm $(docker ps -aq)
f725c5d8814b
Summary of Docker kill command
The docker kill command can be used to kill one or more running Docker containers.
Docker kill command syntax:
docker kill [OPTIONS] CONTAINER [CONTAINER...]
Docker rm command
Overview of the Docker rm command
The docker rm command can be used to remove one or more stopped Docker containers . The CONTAINER after this command can be the container ID or the container name.
Docker rm command syntax
haicoder(www.haicoder.net)# docker rm [OPTIONS] CONTAINER [CONTAINER...]
Docker rm command parameters
parameter | illustrate |
---|---|
-f | Forcefully kill a running container via the SIGKILL signal. |
-l | Remove network connections between containers, not the containers themselves. |
-v:-v | Delete the volume associated with the container. |
the case
delete stopped container
First, use the docker run command to create and run a docker container.
haicoder(www.haicoder.net)# docker run -d -it --name haicoder ubuntu
b91d9d62989f6df7ac38b13f20c656452779df10f8da23c4f1acc6f71b99c87f
Use the docker ps command to view the currently running containers, as shown in the following figure:
Now we use the docker kill command to kill the docker container that was just running.
haicoder(www.haicoder.net)# docker kill haicoder
#输出
haicoder
Use the docker ps command again to view the currently running containers, as shown in the following figure:
At this point, we found that there were no running Docker containers, that is, the container was killed.
Use the docker ps -a command again to view all containers, as shown in the following figure:
Use the docker rm command to delete the docker container.
haicoder(www.haicoder.net)# docker rm b91d9d62989f
b91d9d62989f
Use the docker ps -a command again to view all containers, as shown in the following figure:
At this point, there is no container, that is, the container just created has been deleted. That is, in the above case, we use the docker rm command to delete a stopped docker container.
delete running container
First, use the docker run command to create and run a docker container.
haicoder(www.haicoder.net)# docker run -d -it --name haicoder ubuntu
1e356bbb6a31d4e32487e3406294b44a273910a4a5967a9d4d92d8bee9d7ed2c
Use the docker ps command to view the currently running containers, as shown in the following figure:
Now we use the docker rm command to kill the running docker container.
haicoder(www.haicoder.net)# docker rm haicoder
Error response from daemon: You cannot remove a running container 1e356bbb6a31d4e32487e3406294b44a273910a4a5967a9d4d92d8bee9d7ed2c. Stop the container before attempting removal or use -f
At this time, the command line directly reports an error, prompting us to use the docker rm -f command. We use the docker rm -f command to delete a running docker container.
haicoder(www.haicoder.net)# docker rm -f haicoder
haicoder
Use the docker ps -a command again to view all containers, as shown in the following figure:
At this point, there is no container, that is, the running docker container just created has been forcibly deleted by the docker rm -f command. That is, in the above case, we use the docker rm command to delete a running docker container.
Summary of Docker rm command
The docker rm command can be used to remove one or more stopped Docker containers.
Docker rm command syntax:
docker rm [OPTIONS] CONTAINER [CONTAINER...]
Docker pause command
Overview of the Docker pause command
The docker pause command can be used to pause all processes in a Docker container . The CONTAINER after this command can be the container ID or the container name.
Docker pause command syntax
haicoder(www.haicoder.net)# docker pause [OPTIONS] CONTAINER [CONTAINER...]
the case
Pause the container process
First, use the docker run command to create and run a docker container, and execute the command at the same time to output a sentence of 'hello haicoder' every 3 seconds.
haicoder(www.haicoder.net)# docker run --name haicoder -d ubuntu /bin/bash -c "while true; do echo hello haicoder; sleep 3; done"
86706cc2823c4cac327e9374d443bc1965c9c5f1c3caf1dce13d5b0f65a4934c
Use the docker logs -f command to view the logs of the currently running container
haicoder(www.haicoder.net)# docker logs -f haicoder
The following figure is displayed, as shown:
Now we use the docker pause command to pause the process of the just running docker container.
haicoder(www.haicoder.net)# docker pause haicoder
haicoder
Use the docker logs -f command again to view the logs of the currently running container, as shown in the following figure:
At this point, we found that using docker logs -f to view the log information in the container, there will be no new log output, that is, the running process in the container is stopped by the docker pause command.
That is, in the above case, we use the docker pause command to suspend all processes in the container. Finally, we use the docker rm command to delete the docker container.
haicoder(www.haicoder.net)# docker unpause `docker ps -aq` ; docker stop `docker ps -aq` ; docker rm `docker ps -aq`
Docker pause command summary
The docker pause command can be used to pause all processes in a container.
Docker pause command syntax:
docker pause [OPTIONS] CONTAINER [CONTAINER...]
Docker unpause command
Overview of the Docker unpause command
The docker unpause command can be used to resume all processes in a Docker container . The CONTAINER after this command can be the container ID or the container name.
Docker unpause command syntax
haicoder(www.haicoder.net)# docker unpause [OPTIONS] CONTAINER [CONTAINER...]
the case
Resume a suspended container process
First, use the docker run command to create and run a docker container, and execute the command at the same time to output a sentence of 'hello haicoder' every 3 seconds.
haicoder(www.haicoder.net)# docker run --name haicoder -d ubuntu /bin/bash -c "while true; do echo hello haicoder; sleep 3; done"
e6531501ca5cd9d2c7a245403650bf266b16ee070a52968a4b138ca51d7bb9b4
Use the docker logs -f command to view the logs of the currently running container, as shown in the following figure:
Now we use the docker pause command to pause the process of the docker container that was just running.
haicoder(www.haicoder.net)# docker pause haicoder
haicoder
Use the docker logs -f command again to view the logs of the currently running container, as shown in the following figure:
At this point, we found that using docker logs -f to view the log information in the container, there will be no new log output, that is, the running process in the container is stopped by the docker pause command.
We use the docker unpuase haicoder command to start the process of the docker container that was just suspended.
haicoder(www.haicoder.net)# docker unpause haicoder
haicoder
Use the docker logs -f command again to view the logs of the currently running container, as shown in the following figure:
At this point, we found that the docker container has logs again, that is, the suspended process was resumed by the docker unpause command. That is, in the above case, we use the docker unpause command to resume all processes in the suspended container.
Finally, we use the docker rm command to delete the docker container.
haicoder(www.haicoder.net)# docker stop `docker ps -aq` ; docker rm `docker ps -aq`
e6531501ca5c
e6531501ca5c
Summary of Docker unpause command
The docker unpause command can be used to resume all processes in the container.
Docker unpause command syntax:
docker unpause [OPTIONS] CONTAINER [CONTAINER...]