如何从docker-compose.yml中添加标签到docker push命令中
当对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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以在docker-compose文件中为您的图像名称添加使用变量替换,例如:
使用
repo
和tag_from_file
定义为env vars:它应该起作用。
您还可以使用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:
And build with
REPO
andtag_from_file
defined as env vars: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