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 }}

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.