Build a Docker Image and Push it to ACR Using GitHub Actions

In this post, we will build a Docker image using GitHub Actions and push it to Azure Container Registry (ACR).

In the last few articles about GitHub Actions, we learned how to connect GitHub to Azure using secrets to review these articles to understand what we did fully.


To connect to ACR, you will need to note down your ACR details, including username, hostname and password and save the username and password as secrets (GitHub Actions -> Settings -> Secrets). In our case, I am using the following secrets to store the ACR username and password.



We used secrets to authentication to Azure in this article. If you need to create an ACR with Terraform, check this post.


If your secrets and ACR are ready, go ahead and copy the following workflow to your repository and run it. Make sure you change the ACR server details and image name before saving it.

In my case, my repository containers a Dockerfile that is located at the root of the repository. GitHub Actions will find it and run the build commands. If your image is Windows-based, make sure you change the run-on line to windows and not Ubuntu.

name: Build a Docker image and Push it to ACR

    branches: [ master ]
    branches: [ master ]


    runs-on: ubuntu-latest
      - uses: actions/checkout@v2
      - uses: azure/docker-login@v1
          username: ${{ secrets.ACR_USERNAME }}
          password: ${{ secrets.ACR_PASSWORD }}

      - run: |
          docker build . -t${{ github.sha }}
          docker push${{ github.sha }}

1 thought on “Build a Docker Image and Push it to ACR Using GitHub Actions”

  1. I’m having an issue on the build part. I built my .NET API just fine but on the docker build part I get this:

    Step 7/17 : COPY [“test/test.csproj”, “test/”]
    COPY failed: file not found in build context or excluded by .dockerignore: stat test/test.csproj: file does not exist

    I don’t have any “*.csproj” file in the .dockerignore file.
    Any ideas on this? I’m working with a monorepo.
    Thanks in advance.

Comments are closed.