Docker docker-compose.yml: `version` is obsolete" 解决办法

本文最后更新于 2024年5月12日,已超过 3 月没有更新,如果文章内容失效,请反馈给我们,谢谢!

这通常意味着使用的 docker-compose 版本不支持该文件中声明的版本号。

阅读官方文档:

https://docs.docker.com/compose/compose-file

https://docs.docker.com/compose/compose-file/04-version-and-name

有这么一句话:

Version top-level element (obsolete)

The top-level version property is defined by the Compose Specification for backward compatibility. It is only informative and you'll receive a warning message that it is obsolete if used.

Compose doesn't use version to select an exact schema to validate the Compose file, but prefers the most recent schema when it's implemented.

Compose validates whether it can fully parse the Compose file. If some fields are unknown, typically because the Compose file was written with fields defined by a newer version of the Specification, you'll receive a warning message.

总结就是

version 字段已经弃用了,Compose 能验证它是否可以完全解析 Compose 文件。

docker compose 能做到向下兼容,警告你不要写上版本号

解决办法

把 version 那行注释或者删掉

# version: '3.9'
© 版权声明
分享是一种美德,转载请保留原链接
THE END

文章不错?点个赞呗
点赞 0 分享

发表评论

您的电子邮箱地址不会被公开。 必填项已用 * 标注

滚动至顶部