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 machine

    Realize

    A convenient way to solve this problem is to specify dataDir when 'docker build image'`
    Dockerfile

    FROM 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

点赞(2)

评论列表 共有 0 评论

暂无评论

微信服务号

微信客服

淘宝店铺

support@elephdev.com

发表
评论
Go
顶部