In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-02 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/02 Report--
Scenario description
In a certain system, the functional service is started by docker stack deploy xxx, the service of a domestic database is started by docker run xxx alone, and the database service does not mount the storage location.
As a result, the client restarted the server. When logging in to the server to restart the service, a problem was found that the data in the database might disappear (if started with docker run again).
Solution.
Try 1
At first, I thought that the data must have been lost, so we can only toss the data again, but the workload is too heavy.
But there is no way, next time boot, just mount the storage to the hard drive, Orz
However, after communicating with colleagues, I found a simpler (but not permanent) solution, see try 2
Try 2
Colleagues mentioned that you can use docker start container_name to start the container again so that the data is still there. I tried it later, and sure enough, the data was still there. Although it is only a temporary solution.
After thinking about it, 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, in this place, 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.
Verification test
Pack a random image, start the container, create a file, stop, start again, and check to see if the file exists
# launch the container ➜docker_start_test docker run-itd-- name docker_run_test 4cbf48630b46 ping 127.0.0.1d6278f537113122d4ccbe00950790750215c5a09002bcbd1ef6f9e660fc9eaac➜ docker_start_test docker ps-aCONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMESd6278f537113 4cbf48630b46 "ping 127.0.0.1" 3 seconds ago Up 2 seconds docker_run_test# into the container to add the file ➜docker_start_test Docker exec-it docker_run_test / bin/shsh-4.2# pwd/sh-4.2# touch testsh-4.2# exitexit# restart container ➜docker_start_test docker stop docker_run_testdocker_run_test➜ docker_start_test docker ps-a | grep docker_run_testd6278f537113 4cbf48630b46 "ping 127.0.0.1" About a minute ago Exited (137) 12 seconds ago docker_ Run_test# goes in to see if the file exists ➜docker_start_test docker start docker_run_testdocker_run_test➜ docker_start_test docker exec-ti docker_run_test / bin/shsh-4.2# lsanaconda-post.log bin dev etc home lib lib64 lost+found media mnt opt proc root run sbin srv sys test tmp usr var
You can see that the file test still exists; if you stop the container, use docker rm to delete the container, and restart a container with the same name, you can see that there are no more test files in the container.
# stop / rm drop container ➜docker_start_test docker stop docker_run_testdocker_run_test➜ docker_start_test docker ps-a | grep docker_rund6278f537113 4cbf48630b46 "ping 127.0.0.1" 7 minutes ago Exited (13713 seconds ago docker_run_test ➜docker_start_test docker rm d6278f537113d6278f537113#) launch a new container with the same name➜ docker_start_test docker run-itd-name Docker_run_test 4cbf48630b46 ping 127.0.0.199a6f5df0a86e4c07abf184e322a23e4fbec89ff354691459cdac8fcd8687ba3# enters the container to verify ➜docker_start_test docker exec-ti docker_run_test / bin/shsh-4.2# lsanaconda-post.log bin dev etc home lib lib64 lost+found media mnt opt proc root run sbin srv sys tmp usr varsh-4.2# ls testls: cannot access test: No such file or directory
Description of docker run
From the official website, the function of the start command is:
Start one or more stopped containers
Emmm, straight and straight, there's nothing to say.
PS
In fact, the best way is to mount the storage directory of the container. In addition, in general, it seems that database services should not be started with a container
Summary
The above is the editor introduced to you how to hang up the data in the container started by docker run. I hope it will be helpful to you. If you have any questions, please leave me a message and the editor will reply to you in time. Thank you very much for your support to the website!
If you think this article is helpful to you, you are welcome to reprint it, please indicate the source, thank you!
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.