Docker container cannot be solved by stop or kill problem
- 2021-06-28 14:28:15
- OfStack
Docker version 1.13.1
Problem process
An environment an mysql container cannot be stop or kill or rm
sudo docker ps | grep mysql
View the container
7844250860f8 mysql:5.7.22 "/.r/r docker-entr..." 41 minutes ago Up 8 minutes r-dlrel-mysql-1-66df8f33
After processing with commands such as docker stop / docker kill / docker rm - f, the container restarts automatically
View the container immediately, running at Up Less than a second, indicating that the container started immediately
7844250860f8 mysql:5.7.22 "/.r/r docker-entr..." 42 minutes ago Up Less than a second r-dlrel-mysql-1-66df8f33
kill The physical process corresponding to this container still restarts automatically
Get the physical process by: 1. The State.Pid field in docker inspect is the physical process ID;2.ps command
View the container restart policy, with the policy no, that is, it will not restart automatically
If you need to update the restart policy for a running container, you can use this command:
docker update �restart=no my-container
"RestartPolicy": {
"Name": "no",
"MaximumRetryCount": 0
},
Magic problem solving between programmers
Have you seen this before?
When I come to my colleagues and explain the puzzling problem clearly, I suddenly realize it. The problem is clear and simple, but the program is running in a problem, and then find a colleague to help check the basic configuration, I insight again.This time I belong to the first type, just finished saying the problem, and immediately remembered: Wipe, is the container arranging tool Rancher scheduling, the container will automatically restart after hanging.
Log in to rancher1 and see if so, "Oolong" question.Although this is not a problem, Docker does have problems with stop and there is a lot of data.
Extended reading: Docker Restart Policy
A lot of Docker Restart Policy knowledge and Bug were learned during the solution process. This article is easy to understand: Ensuring Containers Are Always Running with Docker's Restart Policy
For the record, learn four Restart Policy from Docker.
no
no is the default policy and will not be an restart container under any circumstances
on-failure
on-failure indicates that restart will be used if the container exit code is abnormal and nothing will be done if the container exit code is normal.
sudo docker run -d --name testing_restarts --restart on-failure:5 testing_restarts
85ff2f096bac9965a9b8cffbb73c1642bf7b64a2173bbd145961231861b95819
on-failure[: max-retries], max-retries indicates the maximum number of restarts.
The benefit of on-failure is that if the container terminates with normal exit code, restart will not be available
always
Whatever the container exit code is, restart is automatically generated.List several scenarios:
Container terminates with an abnormal status code (e.g. termination due to insufficient application memory) Container is restarted by normal stopped, then machine or Docker service Container is down and then restart machine or Docker servicealways exposes all restart containers, but if on-failure and no policies are applied, the containers will not be able to restart after the machine is restarted.
unless-stopped
unless-stopped is similar to always in that only one scene, unless-stopped, is a bit special:
If the container is stopped and then the machine or docker service is restarted, the container will not be restart in this case