Solution to the problem that Docker container cannot be stopped or killed

Solution to the problem that Docker container cannot be stopped or killed

Docker version 1.13.1

Problem Process

A MySQL container in a certain environment cannot be stopped, killed, or rm

sudo docker ps | grep mysql to view the container

7844250860f8 mysql:5.7.22 "/.r/r docker-entr..." 41 minutes ago Up 8 minutes r-dlrel-mysql-1-66df8f33

After using docker stop / docker kill / docker rm -f and other commands, the container will automatically restart immediately

Check the container immediately. The running time is: 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 the container and restart it automatically

How to get the physical process: 1. The State.Pid field in docker inspect is the physical process ID; 2. ps command

Check the container restart policy. The policy is no, which means 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 programmers solve problems

Have you ever encountered this scenario:

  • I was puzzled by a problem, but as soon as I walked in front of my colleague and explained the problem clearly, I suddenly understood it.
  • The problem was obviously very simple, but there was a problem when the program was running. Then I asked a colleague to help check the basic configuration, and I suddenly realized the answer.

This time I belong to the first type. As soon as I finished asking the question, I immediately remembered: Damn, it was the container orchestration tool Rancher that was doing the scheduling, and the container would automatically restart after it crashed.

I logged into Rancher and saw that it was indeed the case, a "wrong" problem. Although this is not a problem this time, Docker does have the problem of not being able to stop, and there is a lot of information about it.

Further reading: Docker Restart Policy

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

Here we just make a record and learn about the four Restart Policies of Docker.

no

No is the default policy, and the container will not be restarted under any circumstances

on-failure

on-failure means that if the container exit code is abnormal, it will be restarted, and if the container exit code is normal, no processing will be performed.

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 a normal exit code, it will not restart.

always

Regardless of the container exit code, it will automatically restart. Here are a few scenarios:

  1. The container terminates with an abnormal status code (such as the application terminating due to insufficient memory)
  2. The container is stopped normally, and then the machine is restarted or the Docker service is restarted
  3. The container is running normally after it crashes, and then the machine is restarted or the Docker service is restarted

In the above cases, the container will always be restarted. However, if the on-failure and no policies are used, the container will not be restarted 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 stopped normally, and then the machine is restarted or the Docker service is restarted, the container will not be restarted in this case

The above is the full content of this article. I hope it will be helpful for everyone’s study. I also hope that everyone will support 123WORDPRESS.COM.

You may also be interested in:
  • Solution to the problem that the docker container cannot be stopped

<<:  Vue implements adding, displaying and deleting multiple images

>>:  vue-cropper plug-in realizes the encapsulation of image capture and upload component

Recommend

Detailed explanation of the WeChat applet request pre-processing method

question Because some of our pages request data i...

Explore how an LED can get you started with the Linux kernel

Table of contents Preface LED Trigger Start explo...

How to submit the value of a disabled form field in a form Example code

If a form field in a form is set to disabled, the ...

The iframe frame sets the white background to transparent in IE browser

Recently, I need to frequently use iframe to draw ...

What we can learn from Google's new UI (pictures and text)

The most significant website change in 2011 was Go...

A brief talk about calculated properties and property listening in Vue

Table of contents 1. Computed properties Syntax: ...

MySQL 8.0.15 installation and configuration tutorial under Win10

What I have been learning recently involves knowl...

Explanation of the configuration and use of MySQL storage engine InnoDB

MyISAM and InnoDB are the most common storage eng...

JS implements sliding up and down on the mobile terminal one screen at a time

This article shares with you the specific code of...

Teach you step by step to develop a brick-breaking game with vue3

Preface I wrote a few examples using vue3, and I ...

Detailed explanation of adding dotted lines to Vue element tree controls

Table of contents 1. Achieve results 2. Implement...

JS version of the picture magnifying glass effect

This article shares the specific code of JS to ac...