Home > OS >  Docker build and push using github: invalid reference format
Docker build and push using github: invalid reference format

Time:10-20

I want to build my image and push it to dockerhub using github actions.This is invalid reference format

CodePudding user response:

You are not having env.IMAGE data. Below piece of code should do the job.

      - name: Build and push
        run: docker build -t ${{ env.IMAGE }}:${{ github.sha }} .
        env:
          IMAGE: shirzadi/ehsan
           

      - name: Push it!
        run: docker push ${{ env.IMAGE }}:${{ github.sha }}
        env:
          IMAGE: shirzadi/ehsan

CodePudding user response:

You are using environment variables that don't exist. According to docker/build-push-action@v2 documentation it can build, tag and push your image in a single step:

jobs:
  docker:
    steps:
      # ...
      -
        name: Build and push
        uses: docker/build-push-action@v2
        with:
          context: .
          push: true
          tags: shirzadi/ehsan:latest,shirzadi/ehsan:${{ env.GITHUB_SHA }}

The tags key lists 2 tags and use the GITHUB_SHA environment variable. These tags will be pushed as the push key is set to true.

See:

  • Related