Foreword
By default, when docker commits, MySQL data will bypass the file system of the container and will not commit to the image. Normally, MySQL data will not be retained in the image and uploaded to the hub, which has involved data leakage. An alternative method is to start the container initialization data through 'docker entrypoint initdb. D'
The customer has repeatedly asked to directly use the image from 'docker save'. After starting the image, the data from the previous' commit 'will be retained in the container
$ docker load -i mysql.tar
$ docker run -d --network host mysql
There are two main ways for docke to persist data
bind mount
: Mount in the container using the directory of the host, for example:docker run - V / data / MySQL: / var / lib / MySQL
volume
:volume
is also a file system that bypasses the container and directly writes data to the host machine. However, 'volume' is managed by 'docker'. By default, 'volume' under 'docker' is under the ` / var / lib / docker / volumes' directory of the host machineRealize
A convenient way to solve this problem is to specify dataDir when 'docker build image'`
DockerfileFROM mysql:5.7 RUN mkdir /var/lib/mysql-no-volume CMD ["--datadir", "/var/lib/mysql-no-volume"]
For the container started from this image, the data operation is in the container file system. At this time, the commit will retain the data
Post comment 取消回复