skip to Main Content

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

2

Answers


  1. 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
    
    Login or Signup to reply.
  2. 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
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search