Get the App
SLTechnology News&Howtos  ›  Servers  › 

What if the docker container hangs up?

Shulou Source: shulou.com Published: 2022-05-31 20:08:21 09月22日 Update

This article focuses on "what to do if the docker container is hung up". Interested friends may wish to take a look at it. The method introduced in this paper is simple, fast and practical. Next, let the editor take you to learn "what to do if the docker container hangs up"!

Will the docker container hang up? The docker container may hang up, such as the container started by docker run. What worries us most about the failure of containers is the problem of data. Here's an example.

In a certain system, the functional service is started using docker stack deploy xxx, the service of a database is started using docker run xxx alone, and the database service does not mount the storage location; as a result, when you restart the server and log in to the server to restart the service, it is found that the data in the previous database may disappear (if you start it using docker run again).

Solution 1

When data is lost, the most direct idea is to reverse the data again, but this is a lot of work. The next time you boot, mount the storage to the hard drive. But there is also a simpler way.

Solution 2

You can use docker start container_name to start the container again so that the data is still there. But this is only a temporary solution.

The image initiated by docker, if the data is not mapped out, will be stored in the default volume;, even if the container is restarted with docker restart xxx, the changed data will still be there.

In other words, when the server restarts and the container dies (use docker ps to check, the container status is Exited), but in fact, the previous data will still be under the default volume, and the changed data will be lost only when the container is deleted.

Actually, the best way is to mount the storage directory of the container. In addition, in general, database services should not be started using containers.

At this point, I believe you have a deeper understanding of "what to do when the docker container is hung up". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!

Tags: Containers data services methods databases storage what to do time servers contents methods changes learning practical large deeper generally speaking that is that is Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno MariaDB NVidia Docker Linux Apple