💸Save up to $132K/month in CI costs!👉 Try Free
Skip to main content
← Back to workflows

How to Use GitHub Actions to Login to a Docker Registry

docker-login-action -
GitHub Action

Optimize Your CI/CD Pipeline

Get instant insights into your CI/CD performance and costs. Reduce build times by up to 45% and save on infrastructure costs.

45% Faster Builds
60% Cost Reduction
Usage
name: 'Usage of login-action GitHub Action'
on:
push:
branches:
- main
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

login-action logo

Docker Login Action

GitHub Action to login against a Docker registry


What is Docker Login Action?

For workflows involving Docker, such as building and pushing images, it's essential to securely log in to a Docker registry. GitHub Actions provides a straightforward way to automate the login process, ensuring that our Docker operations are authenticated without manually entering credentials each time.

How to Authenticate to GitHub Container Registry Using GitHub Actions

For projects that require Docker container management, using GitHub Actions to authenticate to the GitHub Container Registry (GHCR) can streamline our workflow. GHCR integration allows for better handling of Docker images within GitHub, providing a seamless CI/CD experience. Below is a guide on how to set up authentication for GHCR using GitHub Actions.

- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

How to Login to GitLab's Docker Registry Using GitHub Actions

For projects that utilize both GitLab and GitHub, it's beneficial to know how to configure GitHub Actions to login to GitLab's Docker registry. This setup is particularly useful for workflows that involve building Docker images and pushing them to GitLab's registry.

- name: Login to GitLab
uses: docker/login-action@v3
with:
registry: registry.gitlab.com
username: ${{ secrets.GITLAB_USERNAME }}
password: ${{ secrets.GITLAB_PASSWORD }}

How to Authenticate to Azure Container Registry (ACR) Using GitHub Actions

For projects that involve deploying or managing Docker containers via Microsoft's Azure platform, integrating GitHub Actions to authenticate to Azure Container Registry (ACR) can significantly streamline our deployment pipeline. Below is a detailed guide on how to configure this setup effectively.

- name: Login to ACR
uses: docker/login-action@v3
with:
registry: <registry-name>.azurecr.io
username: ${{ secrets.AZURE_CLIENT_ID }}
password: ${{ secrets.AZURE_CLIENT_SECRET }}

How to Authenticate to Google Container Registry (GCR) Using GitHub Actions

Google Artifact Registry, which evolved from Google Container Registry, provides a robust, fully-managed service for both container images and non-container artifacts. For projects currently utilizing Google Container Registry, transitioning to Google Artifact Registry might involve updating authentication methods. This guide covers two primary methods of authentication suitable for GitHub Actions: Workload Identity Federation and Service Account Based Authentication.

Authentication Using Workload Identity Federation

- name: Login to ECR
uses: docker/login-action@v3
with:
registry: gcr.io
username: _json_key
password: ${{ secrets.GCR_JSON_KEY }}

Authentication Using a Service Account

- name: Authenticate to Google Cloud
id: auth
uses: google-github-actions/auth@v1
with:
token_format: access_token
workload_identity_provider: <workload_identity_provider>
service_account: <service_account>
- name: Login to GAR
uses: docker/login-action@v3
with:
registry: <location>-docker.pkg.dev
username: oauth2accesstoken
password: ${{ steps.auth.outputs.access_token }}

How to Authenticate to AWS Elastic Container Registry (ECR) Using GitHub Actions

Integrating AWS Elastic Container Registry (ECR) with GitHub Actions allows you to automate the Docker image deployment process efficiently. Below, you will find steps on setting up GitHub Actions to push to ECR using different authentication methods.

Basic ECR Authentication

- name: Login to ECR
uses: docker/login-action@v3
with:
registry: <aws-account-number>.dkr.ecr.<region>.amazonaws.com
username: ${{ secrets.AWS_ACCESS_KEY_ID }}
password: ${{ secrets.AWS_SECRET_ACCESS_KEY }}

Multi-Account ECR Login

- name: Login to ECR
uses: docker/login-action@v3
with:
registry: <aws-account-number>.dkr.ecr.<region>.amazonaws.com
username: ${{ secrets.AWS_ACCESS_KEY_ID }}
password: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
env:
AWS_ACCOUNT_IDS: 012345678910,023456789012

Using AWS CLI Actions for Credentials Management

- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v4
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: <region>
- name: Login to ECR
uses: docker/login-action@v3
with:
registry: <aws-account-number>.dkr.ecr.<region>.amazonaws.com

Using AWS Public Elastic Container Registry (ECR)

- name: Login to Public ECR
uses: docker/login-action@v3
with:
registry: public.ecr.aws
username: ${{ secrets.AWS_ACCESS_KEY_ID }}
password: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
env:
AWS_REGION: <region>

How to Authenticate to OCI Oracle Cloud Infrastructure Registry (OCIR) Using GitHub Actions

Here is a guide on how to set up GitHub Actions for pushing Docker images to the Oracle Cloud Infrastructure Registry (OCIR).

- name: Login to OCIR
uses: docker/login-action@v3
with:
registry: <region>.ocir.io
username: ${{ secrets.OCI_USERNAME }}
password: ${{ secrets.OCI_TOKEN }}

How to Authenticate to Quay.io Using GitHub Actions

Here is a guide on how to set up GitHub Actions for pushing Docker images to Quay.io using a Robot account.

- name: Login to Quay.io
uses: docker/login-action@v3
with:
registry: quay.io
username: ${{ secrets.QUAY_USERNAME }}
password: ${{ secrets.QUAY_ROBOT_TOKEN }}

How to Authenticate to the DigitalOcean Container Registry

To authenticate to the DigitalOcean Container Registry, use the DIGITALOCEAN_USERNAME and DIGITALOCEAN_ACCESS_TOKEN.

- name: Login to DigitalOcean Container Registry
uses: docker/login-action@v3
with:
registry: registry.digitalocean.com
username: ${{ secrets.DIGITALOCEAN_USERNAME }}
password: ${{ secrets.DIGITALOCEAN_ACCESS_TOKEN }}