This is the 6th day of my participation in the August More Text Challenge
DockerFile
DockerFile used to build docker image build file, in fact, is a command script, through the script can generate a mirror, mirror is a layer of a layer, corresponding to the script is a command, each command is a layer of the following let’s do a test
1. Create a folder in the test path
# cb @ bangdeMacBook-Pro in~ /test/docker-test-volume [6:57:20]
$ pwd
**> /Users/cb/test/docker-test-volume**
Copy the code
2. Create a new file dockerFile01 and enter the following information
FROM centos
VOLUME ["/volume01","/volume02"]
CMD echo "---end---"
CMD /bin/bash
Copy the code
3. Run commands to build an image
Docker build -f dockerFile01 -t cbaj/centos:1.0Copy the code
Take a look and you can see the image you just generated
Then start the container you made
docker run -it 703f234db31c /bin/bash
Copy the code
The directory of the data volume must have a synchronous directory with the external volume. We did not specify a directory in the previous operation, so it is an anonymous mount.
We create a file in volume01 inside the container
Then use the Docker inspect command to check the container information, and you can see the mapping as shown in the figure below. As described above, anonymous mount generates random directories
Then go to the host directory and look at the directory and see that the files in the container have been successfully synchronized
If it is a MAC, you need to view the docker data volume usage as described in the previous article
We’ll be using this a lot in the future, because we usually build our own mirrors!
Container data volume
So how do multiple Docker containers directly achieve data synchronization? So you can look at the picture below and understand it a little bit, and then we can actually see it
Let’s launch the image we just built ourselves and call it Docker01
Docker run -it --name docker01 cbaj/centos:1.0Copy the code
Run the –volumes-from command to add volumes to the docker02 container and run the –volumes-from command to inherit the docker01 container.
Docker runit --name docker02 --volumes- From docker01 cbaj/centos:1.0Copy the code
Create files in the volume01 directory of docker01. The generated files will be synchronized to the corresponding folder of docker02
Start another Docker03
Docker runit --name docker03 --volumes- From docker01 cbaj/centos:1.0Copy the code
Docker03 will synchronize the existing files in docker01, also in docker03 new files in docker01, docker02 synchronization; Docker01 = docker01 = docker01 = docker01 = docker01 = docker01 = docker01 = docker01 The content that we synchronize under its children can also be synchronized within Docker01. Even when we delete the docker01 container, the contents of the docker02 and Docker03 container remain (this is the difference between synchronization and mapping)
Multiple mysql implements data sharing
docker run -d -p 3310:3306 -v /Users/chenbang/home/mysql/conf:/etc/mysql/conf.d -v / Users/chenbang/home/mysql/data: / var/lib/mysql - e MYSQL_ROOT_PASSWORD = 123456 - name mysql01 mysql: 5.7 docker run - d - p 3306 -e -e MYSQL_ROOT_PASSWORD=123456 --name mysql02 --volumes-from mysql01 mysql:5.7Copy the code
conclusion
Configuration information is transferred between containers. The life cycle of the data volume container lasts until there is no container. Once data is synchronized to the local, the local data is not affected by the container
This is not to return to the guests, but because of the liquor to stay dust.