更改镜像后如何升级docker容器 [英] How to upgrade docker container after its image changed

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

问题描述

假设我已经拉取了官方 mysql:5.6.21 镜像.

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

我通过创建多个 docker 容器部署了这个镜像.

I have deployed this image by creating several docker containers.

这些容器已经运行了一段时间,直到 MySQL 5.6.22 发布.mysql:5.6 的官方镜像随着新版本更新,但我的容器仍然运行 5.6.21.

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.

如何将映像中的更改(即升级 MySQL 发行版)传播到所有现有容器?执行此操作的正确 Docker 方法是什么?

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.

Docker 升级容器的方式好像如下:

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

  • About volumes (Docker docs)
  • Tiny Docker Pieces, Loosely Joined (by Tom Offermann)
  • How to deal with persistent storage (e.g. databases) in Docker (Stack Overflow question)

在容器内升级应用程序(例如使用 yum/apt-get upgrade)被认为是一种反模式.应用程序容器应该是不可变的,这将保证可重现的行为.一些官方应用程序镜像(尤其是 mysql:5.6)甚至没有设计为自我更新(apt-get upgrade 不起作用).

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.

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

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