我从docker hub提取了mysql并能够运行此容器。创建一些数据库和表之后,我想将此容器提交到新镜像,以持久保存更改。通过这样做,我希望可以将新镜像运送到包含所有数据的其他成员。我使用以下命令:
$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
3aca4ff8790d mysql "/entrypoint.sh mysql" 6 months ago Up 2 minutes 0.0.0.0:3306->3306/tcp lonely_liskov
$docker commit 3aca4ff8790d cooltoo/cooltoo_db:LATEST
当我运行这个新图像时,我所有的更改和设置都没有。如何将我所有的更改和设置持久化到新镜像中?
最佳答案
亨利是对的。 MySQL容器Dockerfile将/ var / lib / mysql配置为一个卷。
最好的选择(以及业界最佳实践)是将所做的更改放入Dockerfile中(从“FROM mysql”开始)。引用docs:
When a container is started for the first time, a new database with the specified name will be created and initialized with the provided configuration variables. Furthermore, it will execute files with extensions .sh, .sql and .sql.gz that are found in /docker-entrypoint-initdb.d. Files will be executed in alphabetical order.
因此,如果您将数据/模式/任何内容放入mysqldump,然后放入
ADD foo.sql /docker-entrypoint-initdb.d/foo.sql
...在那里,你应该是黄金的。
关于docker - 提交一个Docker容器但没有任何更改,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39071522/