Docker container data volume If the data is all in the container, then the data will be lost when we delete the container, so we hope that the data can be persistent.
Using Data VolumesMethod 1: Mount directly using command -vdocker run -it -v host directory: container directory#test[root@sumarua home]# docker run -it -v /home/ceshi:/home centos /bin/bash # After starting, we can check it through docker inspect container id] Example MySQL data persistence [root@sumarua home]# docker run -d -p 3310:3306 -v /home/mysql/conf:/etc/mysql/conf.d -v /home/mysql/data:/var/lib/mysql -e MYSQL_ROOT_PASSWORD=666666 --name mysql mysql5.7 Named and anonymous mounts #Anonymous mount -v container path docker run -d -p --name nginx01 -v /etc/nginx nginx #View all volumes docker volume ls # Named mount# Through -v volume name: path in container docker run -d -p --name nginx02 -v juming-nginx:/etc/nginx nginx #View docker volume ls We can check the specific location where the volume is mounted docker volume inspect [volume name] All volumes in Docker containers are in -v path in container #anonymous mount -v volume name: path in container #named mount -v /host path: path in container #specified path mount expand: # Change the read and write permissions through -v container path: ro rw ro readonly #read-only rw readwrite #readable and writable #Readable and writable by default #Once the container permissions are set, the container will limit the content we mount #ro This path can only be operated through the host machine, and cannot be operated inside the container. Method 2: Dockerfile Dockerfile is a build file and command script used to build a docker image. # Create a dockerfile file. The name can be random. Dockerfile is recommended. # Content command (uppercase) parameter in the file FROM centos VOLUME ["volume01","volume02"] CMD echo "----end----" CMD /bin/bash # Each command here is a layer of the image Data volume container # Usage [root@sumarua]#docker run -it --name docker02 --volumes-from docker01 sumarua/centos Realize data synchronization and data sharing between containers Deleting files from a data volume container does not affect data access in other containers mounted on this container. It is a copy concept and a backup copy mechanism. The configuration information is transferred between containers. The life cycle of the data volume container lasts until no container is used. SummarizeThis is the end of this article about container data volumes in Docker. For more relevant Docker data volumes, please search for previous articles on 123WORDPRESS.COM or continue to browse the following related articles. I hope you will support 123WORDPRESS.COM in the future! You may also be interested in:
|
<<: 40 web page designs with super large fonts
>>: uni-app WeChat applet authorization login implementation steps
The correspondence between tensorflow version and...
First configure the project artifacts Configuring...
Today I found that WordPress could not connect to...
1. Make a repo file Refer to the official install...
Even though it's not Halloween, it's wort...
The mini program collected user personal informat...
Table of contents Preface Prepare Implementation ...
This article uses examples to describe how to cre...
Two days ago, I took advantage of the Double 11 s...
background: Sometimes we need to display json dat...
Background Controller @RequestMapping("/getP...
Using CSS layout to create web pages that comply w...
Multi-way search tree Height of a complete binary...
Table of contents Native JS How to send a get req...
Some fault code tables use the following design p...