在其图像更改后如何升级码头容器 [英] How to upgrade docker container after its image changed

查看:100
本文介绍了在其图像更改后如何升级码头容器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我已经提交了官方的 mysql:5.6.21 image



我已经通过创建几个Docker容器来部署此映像。



这些容器已经运行了一段时间,直到MySQL 5.6.22发布。 mysql的官方形象:5.6被新版本更新,但我的容器仍然运行5.6.21。



如何传播图像中的更改(即升级MySQL发行版)到我现有的所有容器?这样做的Docker方法是什么?

解决方案

评估答案并研究主题后,我想总结一下。



Docker升级容器的方式似乎如下:



应用程序容器不应该存储申请资料。这样,您可以随时通过执行以下操作来替换其新版本的应用程序容器:

  docker pull mysql 
docker stop my-mysql-container
docker rm my-mysql-container
docker run --name = my-mysql-container --restart = always \
-e MYSQL_ROOT_PASSWORD = mypwd -v / my / data / dir:/ var / lib / mysql -d mysql

主机上的数据(在卷中的目录中)或特殊的仅数据的容器。了解更多信息 here 这里 here



升级应用程序在容器内的yum / apt-get升级被认为是反模式。应用程序容器应该是不可变的,这将保证可重现的行为。一些官方应用程序映像(特别是mysql:5.6)甚至不能自行更新(apt-get升级将无法正常工作)。



我想感谢所有给出答案的人,所以我们可以看到所有不同的方法。


Let's say I have pulled the official mysql:5.6.21 image.

I have deployed this image by creating several docker containers.

These containers have been running for some time until MySQL 5.6.22 is released. The official image of mysql:5.6 gets updated with the new release, but my containers still run 5.6.21.

How do I propagate the changes in the image (i.e. upgrade MySQL distro) to all my existing containers? What is the proper Docker way of doing this?

解决方案

After evaluating the answers and studying the topic I'd like to summarize.

The Docker way to upgrade containers seems to be the following:

Application containers should not store application data. This way you can replace app container with its newer version at any time by executing something like this:

docker pull mysql
docker stop my-mysql-container
docker rm my-mysql-container
docker run --name=my-mysql-container --restart=always \
  -e MYSQL_ROOT_PASSWORD=mypwd -v /my/data/dir:/var/lib/mysql -d mysql

You can store data either on host (in directory mounted as volume) or in special data-only container(s). Read more about it here, here, and here.

Upgrading applications (eg. with yum/apt-get upgrade) within containers is considered to be an anti-pattern. Application containers are supposed to be immutable, which shall guarantee reproducible behavior. Some official application images (mysql:5.6 in particular) are not even designed to self-update (apt-get upgrade won't work).

I'd like to thank everybody who gave their answers, so we could see all different approaches.

这篇关于在其图像更改后如何升级码头容器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆