且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

在其图像更改后如何升级码头容器

更新时间:2023-11-22 22:54:04

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



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.