[英]How to specify a docker image in docker-compose file using regex
I have a docker image which I build using an automated pipeline job. 我有一个使用自动管道作业构建的docker镜像。
It is called: 它被称为:
REPOSITORY TAG IMAGE ID
test-001-com:3000/img 1.23-SNAPSHOT 2f83de9h895e
NOTE: The TAG changes daily so tomorrow it will be 1.24-SNAPSHOT etc... 注意:TAG每天都在变化,所以明天它将是1.24-SNAPSHOT等......
My Question is: 我的问题是:
How do I use the "image" argument in docker-compose to pass in a regex or something that I don't have to update it everytime to match the TAG. 如何使用docker-compose中的“image”参数传入正则表达式或者我不必每次都更新它以匹配TAG。
docker-compose.yml: 泊坞窗,compose.yml:
services:
test-001:
hostname: "test-001"
container_name: "test-001"
image: "test-001-com:3000/img:1.23-SNAPSHOT"
ports:
- "8000:8000"
version: "2.1"
The above docker-compose.yml works but can I replace: 上面的docker-compose.yml有效,但我可以替换:
image: "test-001-com:3000/img: 1.23-SNAPSHOT " 图片:“test-001-com:3000 / img: 1.23-SNAPSHOT ”
WITH WITH
image: "test-001-com:3000/img: *-SNAPSHOT " or something?! 图片:“test-001-com:3000 / img: * -SNAPSHOT ”还是什么?! <- Doesn't work. < - 不起作用。
You can't do that. 你不能这样做。 The image:
must name an exact version tag, or not have a tag and use the implied ...:latest
version. image:
必须命名一个确切的版本标签,或者没有标签并使用隐含的...:latest
版本。 In general Docker just doesn't support this; 一般来说Docker不支持这个; there is no easy way to search available images by tag and match with a regex or shell glob, you have to know what you're looking for. 没有简单的方法可以通过标签搜索可用的图像并与正则表达式或shell glob匹配,你必须知道你在寻找什么。 Even if you did have a list of tags, there's no universal definition of what's "newest". 即使你确实有一个标签列表,也没有什么是“最新”的通用定义。
You tagged this as "kubernetes". 你把它标记为“kubernetes”。 If this is actually a Kubernetes question, the best way to do this is to set up your continuous deployment system to update the Kubernetes Deployment for you. 如果这实际上是Kubernetes问题,那么最好的方法是设置连续部署系统以便为您更新Kubernetes部署。 Kubernetes will try to start new pods with the new version before deleting old pods, so you should get a zero-downtime upgrade. 在删除旧容器之前,Kubernetes将尝试使用新版本启动新容器,因此您应该进行零停机升级。 ( Helm is a common tool to inject parameters like this; if an upgrade goes wrong it also readily supports rolling back an update.) ( Helm是注入这样的参数的常用工具;如果升级出错,它也很容易支持回滚更新。)
Your example uses Docker Compose. 您的示例使用Docker Compose。 The image:
field is one of the places variable substitution works, so you can set image:
字段是变量替换的地方之一,因此您可以设置
image: "test-001-com:3000/img:${IMAGE_VERSION:-latest}"
and then set IMAGE_VERSION
as an environment variable or in a .env
file in the same directory. 然后将IMAGE_VERSION
设置为环境变量或在同一目录中的.env
文件中。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.