In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)06/01 Report--
Docker Volume, usually translated as a data volume, is used to store persistent data. When we run a database such as MySQL in a Docker container, the data is generally saved on the host through Docker Volume, so that even if the MySQL container is deleted, the data is still saved on the host, effectively ensuring the security of the data. This blog will help you understand Docker Volume through simple practices.
All commands in this article are executed on an online Docker instance of play-with-docker, Docker version 17.05.0-ce.
1. Specify Docker Volume
Docker container can be run using docker run command
docker run -itd --volume /tmp/data1:/tmp/data2--name test ubuntu bash creates a Docker container based on the ubuntu image. The name of the container is test, specified by the--name option. Docker Volume is specified by the--volume option, and the/tmp/data1 directory of the host corresponds to the/tmp/data2 directory in the container. 2. View Docker Volume
Using the docker inspect command, you can view the details of Docker containers:
docker inspect --format='{{json .Mounts}}' test | python -m json.tool[ { "Destination": "/tmp/data2", "Mode": "", "Propagation": "", "RW": true, "Source": "/tmp/data1", "Type": "bind" }] Use the--format option to selectively view desired container information. Mount is the Docker Volume information of the container. python -m json.tool formats the output json string for display. Source represents the directory on the host, which is/tmp/data1. Destination is the directory in the container, i.e./tmp/data2. 3. Native files can be synchronized to containers Create a new hello.txt file in the native/tmp/data1 directory Touch /tmp/data1/hello.txtls /tmp/data1/hello.txthello.txt File visible in container/tmp/data2/directory
With the docker exec command, you can execute commands in containers.
docker exec test ls /tmp/data2/hello.txt
As you can see, changes made in the local directory/tmp/data1/can be synchronized to the container directory/tmp/data2/.
4. Container files can be synchronized to the host. Create a new world.txt file in the container/tmp/data2 directory docker exec test touch /tmp/data2/world.txtdocker exec test ls /tmp/data2/hello.txtworld.txtworld.txt file in the host/tmp/data1/directory ls/tmp/data1/hello.txt world.txt
As you can see, changes in the container directory/tmp/data2/can be synchronized to the host directory/tmp/data1/.
5. conclusion
Docker volumes are essentially directories or files shared between containers and hosts, so that data in Docker volumes can be synchronized in real time between hosts and containers. When creating virtual machines using Virtualbox, you can also configure shared directories, much like Docker Volume.
About Fundebug
Fundebug focuses on JavaScript, Weixin Mini Programs, WeChat Mini games, Alipay Mini Programs, React Native, Node.js and Java real-time BUG monitoring. Since the official launch of Double Eleven in 2016, Fundebug has handled a total of 700 million + error events, which has been recognized by many well-known users such as Google, 360, Jinshan Software and People's Network. Welcome to try it for free!
copyright notice
Please indicate the author Fundebug and the address of this article when reprinting:
https://blog.fundebug.com/2017/06/07/what-is-docker-volume/
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.