docker - 提交一个Docker容器但没有任何更改

标签 docker

我从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/

相关文章:

docker - Nvidia-docker : Unknown runtime specified nvidia

docker - Docker:Openjdk:14基于RHEL的镜像,无法安装yum/wget/netstat

nginx - Docker自动更新Nginx Web服务器容器的主机文件

selenium - 使用 Docker、Selenium 和 Pytest 运行并行测试

ruby-on-rails - Rails 在基于 Rancher 的 Docker 环境和 Postgresql 中运行缓慢

python - 我正在尝试通过 docker compose 运行 Flask 应用程序和 kafka..但无法正确设置

angular - Docker组成了Angular 502 Bad Gateway

docker-compose:如何立即查看文件更改(开发时)

curl - 如何在 Dockerfile 中添加大的 HTTP 文件并将它们从图像层中排除?

node.js - W : Failed to fetch http://deb. debian.org/debian/dists/jessie-updates/main/binary-amd64/Packages 404 未找到 [IP : 151. 101.140.204 80]