使用MySQL:最新作为Docker映像是不好的习惯吗?
docker的构建是为了确保代码可以在任何设备上运行而无需丢失库,错误的版本等问题。
但是,如果您使用“最新”标签而不是固定版本号,那么您实际上不知道事先您最终会使用哪个版本的图像。也许您的代码在编写与“最新”版本兼容的时候,而不是将来。那么使用此标签是不好的做法吗?使用固定版本号是更好的做法吗?
Docker was built to make sure that code can run on any device without any issues of missing libraries, wrong versions, etc.
However if you use the "latest" tag instead of a fixed version number, then you actually don't know on beforehand with which version of the image you'll end up. Perhaps your code is at the time of writing compatible with the "latest" version but not in the future. Is it then a bad practice to use this tag? Is it a better practice to use a fixed version number?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
通常,由于您说明的原因,您可能想避免
...:最新
标签。特别是对于数据库,二进制接口可能存在差异,并且盘存存储肯定存在差异。如果您期望MySQL 5.7,但实际上有MySQL 8.0,您可能会得到一些令人惊讶的行为。如果MySQL 9.0出来,并且您将获得自动升级,则本地安装可能会破裂。
避免
...:最新
的一个通用原因是,Docker将使用正确的标签使用图像的本地副本,而无需检查Docker Hub或其他存储库。因此,在假设的情况下,MySQL 9.0出现了,但是系统A具有旧的mysql:最新
实际上是8.0,docker运行mysql
否则干净的系统b将获得不同的图像,这种不一致可能是有问题的。您可能会在数据库的每个特定补丁发布版本中找到Docker Image标签,但通常只有最新的构建才能获得安全更新。我建议固定在次要版本
mysql:8.0
是一个很好的通用方法。如果您需要非常意识到升级,则可能需要更具体的版本mySQL:8.0.29
。这种方式不太挑剔。我指出REDIS内存数据存储和NGINX HTTP服务器是他们的网络接口和配置保持非常稳定的两件事。如果您使用
nginx:最新
或redis:最新
,即使不同的系统确实与图像的不同版本结束,可能不会出错。Usually, probably, for the reasons you state, you likely want to avoid
...:latest
tags here.For databases in particular, there can be differences in the binary interfaces, and there definitely are differences in the on-disk storage. If you were expecting MySQL 5.7 but actually got MySQL 8.0 you might get some surprising behavior. If a MySQL 9.0 comes out and you get an automatic upgrade then your local installation might break.
A generic reason to avoid
...:latest
is that Docker will use a local copy of an image with the right tag, without checking Docker Hub or another repository. So again in the hypothetical case where MySQL 9.0 comes out, but system A has an oldmysql:latest
that's actually 8.0,docker run mysql
on an otherwise clean system B will get a different image, and that inconsistency can be problematic.You will probably find Docker image tags for every specific patch release of the database, but in general only the most recent build gets security updates. I'd suggest that pinning to a minor version
mysql:8.0
is a good generic approach; you may want the more specific versionmysql:8.0.29
in your production environment if you need to be extremely conscious of the upgrades.Some other software is less picky this way. I'd point at the Redis in-memory data store and the Nginx HTTP server as two things where their network interfaces and configuration have remained very stable. Probably nothing will go wrong if you use
nginx:latest
orredis:latest
, even if different systems do wind up with different versions of the image.