如何从docker-compose.yml中添加标签到docker push命令中

发布于 2025-02-01 20:30:21 字数 624 浏览 1 评论 0原文

当对Docker-compose.yml文件进行更改时,我正在尝试将Docker Image推到Docker Hub(新的主要版本,更改图像标签)。构建运行良好,但是当我尝试按下时,我无法访问图像名称,默认为标签最新,这不是我刚刚构建的。

- name: Build the Docker image
      run: docker compose build
    
- name: Docker push
      run: docker push ${{secrets.DOCKER_USER}}/myreponame

错误

Using default tag: latest
The push refers to repository [docker.io/***/myreponame]
tag does not exist: ***/myreponame:latest
Error: Process completed with exit code 1.

我从docker-compose.yml文件中获取标签或完整的图像名称

所需

的 在Docker组成的构建命令中或从文件中获取这些数据的方法?我不想手动将数据输入到CI/CD。

I am trying to push a docker image to docker hub when there is a change to the docker-compose.yml file (New major version, change image tag). The build runs fine, but when I try to push, I don't have access to the image name, to it defaults to the tag latest, which is not what I just built.

- name: Build the Docker image
      run: docker compose build
    
- name: Docker push
      run: docker push ${{secrets.DOCKER_USER}}/myreponame

I get the error

Using default tag: latest
The push refers to repository [docker.io/***/myreponame]
tag does not exist: ***/myreponame:latest
Error: Process completed with exit code 1.

I need to somehow get the tag or full image name from the docker-compose.yml file:

docker push ${{secrets.DOCKER_USER}}/myreponame:{tag_from_file}

Is there a way to get this data in the docker compose build command, or from the file? I don't want to manually enter data to CI/CD.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

你是我的挚爱i 2025-02-08 20:30:21

您可以在docker-compose文件中为您的图像名称添加使用变量替换,例如:

myapp:
  image: "${REPO}/myreponame:${tag_from_file}"

使用repotag_from_file定义为env vars:

- name: Build the Docker image
  run: REPO=${{secrets.DOCKER_USER}} tag_from_file=something docker compose build

它应该起作用。

您还可以使用Docker所做的GitHub动作来构建和推动图像: https://github.com/marketplace/actions/build-and-push-docker-images

You can add use variable substitution into your docker-compose file for your image name like:

myapp:
  image: "${REPO}/myreponame:${tag_from_file}"

And build with REPO and tag_from_file defined as env vars:

- name: Build the Docker image
  run: REPO=${{secrets.DOCKER_USER}} tag_from_file=something docker compose build

And it should work.

You can also use the Github action made by Docker to build and push your image: https://github.com/marketplace/actions/build-and-push-docker-images

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文