Save mysql combat operations is a mirror image of the container (Copy Method)

If the "container A" and the host were directory is mounted, and the "container A" there are a lot of database table, use the "container A" to preserve the "image A", and to create the "container B" when the will produce a very long time; therefore we do not use this method, we directly use the method of copying a short time;

1, we did not use mysql mirror for mapping a route when the container is created, but the host is automatically mapped to help us the opportunity;
Here Insert Picture Description
2, we can see the FIG host path, container path intuitive; Therefore, we first sink mapping data in the host path copied to the backup folder, instructions: cp -rf /var/lib/docker/volumes/1edaa1bd95398dac1eeb0e0b0e7e1fdd507f79cb3971c54ba358bbeebf81c211/_data /mysqlmeaning: copy data in a path to the front / mysql (note: the instruction to be executed at the host root, and must be added -rf)
Here Insert Picture Description
3, then here we can directly use the save A container A mirrored instruction: docker commit 容器A 新镜像A:标签号
Here Insert Picture Description
4, then we use to create a new image A container B, and its port mapping instructions: docker run -id --name=容器B -p 3306:3306 -e MYSQL_ROOT_PASSWORD=123456 新镜像A:标签号
Here Insert Picture Description
5, and finally quit the command line to the root directory of the host, to execute instructions docker cp /mysql/ mysql2:/var/lib/, to restart copying have finished container, then we go mysql client windows environment under connection, the new connection is found able to see our database table created in the vessel a;
Here Insert Picture Description

Explanation

Because the container A and the host was directory is mounted, it was port mapping in the host machine, and then carried out a database table is created in the windows, will be synchronized to the container A, we have the connections and database table information Full copied to the backup directory / mysql, after which you can copy directly to the new vessels, while avoiding ~~ conduct directory is mounted directly in the creation of the container (said earlier, when the data in a database table is large, the creation process is particularly long ~)

Published 31 original articles · won praise 12 · views 3734

Guess you like

Origin blog.csdn.net/z19950712/article/details/104209831