Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

The solution to the problem that Docker containers cannot be solved by stop or kill

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/02 Report--

Docker version 1.13.1

Problem process

An environment in which a mysql container cannot be stop or kill or rm

Sudo docker ps | grep mysql to view the container

7844250860f8 mysql:5.7.22 "/ .rbind 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 automatically restarts immediately.

Check the container immediately. The running time is: Up Less than a second, which means that the container starts immediately.

7844250860f8 mysql:5.7.22 "/ .rbind r docker-entr..." 42 minutes ago Up Less than a second r-dlrel-mysql-1-66df8f33

Kill the physical process corresponding to the container is still automatically restarted

Get the physical process mode: the State.Pid field in 1.docker inspect is the physical process ID; 2.ps command

Check the container restart policy. The policy is no, that is, it will not restart automatically.

If you need to update the restart policy of a running container, you can use this command: docker update-restart=no my-container

"RestartPolicy": {"Name": "no", "MaximumRetryCount": 0}

The magical way of solving problems between programmers

Have you ever had a scene like this:

When I walked up to my colleagues and explained the problem clearly, I suddenly realized the problem. The problem is obviously very simple, but the program is running is a problem, and then find a colleague to help check the basic configuration, their own epiphany.

This time I belong to the first category. As soon as I finished talking about the problem, I immediately remembered: wipe, the container orchestration tool Rancher is doing scheduling, and the container will restart automatically after it has hung up.

Login to rancher, sure enough, "oolong" problem. Although it is not a problem this time, Docker does have the problem of being unable to stop, and there is a lot of information.

Extended Reading: Docker Restart Policy

In the process of solving, I learned a lot about Docker Restart Policy and Bug. This article is easy to understand: Ensuring Containers Are Always Running with Docker's Restart Policy

Just make a note here and learn about the four Restart Policy of Docker.

No

No is the default policy and does not restart the container under any circumstances

On-failure

On-failure means that if the container exit code is abnormal, it will be restart, and if the container exit code is normal, no processing will be done.

Sudo docker run-d-- name testing_restarts-- restart on-failure:5 testing_restarts85ff2f096bac9965a9b8cffbb73c1642bf7b64a2173bbd145961231861b95819

On-failure [: max-retries], and max-retries represents the maximum number of restarts.

The advantage of on-failure is that if the container terminates with normal exit code, it will not restart

Always

No matter what the container exit code is, it will automatically restart. List a few scenarios:

Container terminates with abnormal status code (such as termination caused by insufficient application memory) Container is normally stopped, then machine restart or Docker service restart container is in normal operation during downtime, and then restart machine or Docker service restart

In the above cases, always side exposure will restart the container, but in the case of on-failure and no policies, the container will not be able to restart after the machine is restarted.

Unless-stopped

Unless-stopped is basically the same as always, except for one scenario where unless-stopped is a little special:

If the container is normally stopped, and then the machine is restarted or the docker service is restarted, in this case the container will not be restart

The above is the whole content of this article, I hope it will be helpful to your study, and I also hope that you will support it.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report