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.
CodePudding user response:
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