steelcityamir
steelcityamir

Reputation: 1218

GitHub Actions - Specify Multiple Tags with docker/build-push-action@v2

Is there a way to specify multiple tags when using docker/build-push-action@v2?

I tried specifying multiple tags separated by a space or comma and they both failed.

Error

buildx failed with: error: invalid tag "***/myapp:1.4.0 ***/myapp:latest": invalid reference format

.github/workflows/publish.yml

- name: Build and push
  id: docker_build
  uses: docker/build-push-action@v2
  with:
    context: .
    push: true
    tags: ${{ secrets.DOCKER_HUB_USERNAME }}/myapp:${{ steps.vars.outputs.tag }} ${{ secrets.DOCKER_HUB_USERNAME }}/myapp:latest

Upvotes: 18

Views: 24639

Answers (2)

Akaisteph7
Akaisteph7

Reputation: 6486

You can also use a "newline-delimited string". I think this is better when you have longer strings:

- name: Build and push
  id: docker_build
  uses: docker/build-push-action@v2
  with:
    context: .
    push: true
    tags: |
      ${{ secrets.DOCKER_HUB_USERNAME }}/myapp:${{ steps.vars.outputs.tag }}
      ${{ secrets.DOCKER_HUB_USERNAME }}/myapp:latest

Upvotes: 23

KafKafOwn
KafKafOwn

Reputation: 545

Check here https://github.com/docker/build-push-action#customizing, add a comma between the tags, like this:

- name: Build and push
  id: docker_build
  uses: docker/build-push-action@v2
  with:
    context: .
    push: true
    tags: ${{ secrets.DOCKER_HUB_USERNAME }}/myapp:${{ steps.vars.outputs.tag }} , ${{ secrets.DOCKER_HUB_USERNAME }}/myapp:latest

Upvotes: 23

Related Questions