In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-22 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
This article shows you whether the data will be lost after the docker container is restarted, the content is concise and easy to understand, and it will definitely brighten your eyes. I hope you can gain something through the detailed introduction of this article.
Will the data of docker container restart be lost? Yes, when you use docker to deploy web applications or mysql databases, you will find that when the container is restarted, the logs or database data generated during the container operation will be emptied.
If you want to persist the data, you need to use volume or data container so that you can reuse the previous data through-v or-volumes-from after the container is closed. Docker mounts the host disk directory, which is used to store data permanently.
Execute Docker Volume when creating a container
Using the docker run command, you can run a Docker container, use the mirror ubuntu/nginx, and mount the local directory / tmp/source to the container directory / tmp/destination
Docker run-itd-volume / tmp/source:/tmp/destination-name test ubuntu/nginx bash
A Docker container is created based on the ubuntu/nginx image. Specifies that the name of the container is test, specified by the-- name option.
Docker Volume is specified by the-- volume (which can be abbreviated to-v) option, and the / tmp/source directory of the host corresponds to the / tmp/destination directory in the container.
View Docker Volume
Using the docker inspect command, you can view the details of the Docker container:
Docker inspect-- format=' {{json .Mounts}} 'test | python-m json.tool [{"Destination": "/ tmp/destination", "Mode": "," Propagation ":"," RW ": true," Source ":" / tmp/source "," Type ":" bind "}]
Using the-- format option, you can selectively view the container information you need. .Mount is the Docker Volume information of the container.
Python-m json.tool can format the output json string display. Source represents the directory on the host, that is, / tmp/source. Destination is the directory in the container, that is, / tmp/destination.
Native files can be synchronized to the container
Create a new hello.txt file in the native / tmp/source directory
Touch / tmp/source/hello.txtls / tmp/source/hello.txt
The hello.txt file is visible in the container / tmp/destination/ directory
Using the docker exec command, you can execute commands in a container.
Docker exectest ls / tmp/destination/hello.txt
So changes to the directory / tmp/source/ in the host can be synchronized to the container directory / tmp/destination/.
Container files can be synchronized to the host
Create a new world.txt file in the container / tmp/destination directory
Docker exec test touch / tmp/destination/world.txtdocker exec test ls / tmp/destination/hello.txtworld.txt
The world.txt file is visible in the host / tmp/source/ directory
Ls / tmp/source/hello.txt world.txt
The above content is whether the data will be lost after the docker container is restarted. Have you learned any knowledge or skills? If you want to learn more skills or enrich your knowledge reserve, you are welcome to follow the industry information channel.
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.