• Stars
    star
    909
  • Rank 48,243 (Top 1.0 %)
  • Language
    TypeScript
  • License
    Apache License 2.0
  • Created over 3 years ago
  • Updated about 2 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

GitHub Action to login against a Docker registry

GitHub release GitHub marketplace CI workflow Test workflow Codecov

About

GitHub Action to login against a Docker registry.

Screenshot


Usage

Docker Hub

To authenticate against Docker Hub it's strongly recommended to create a personal access token as an alternative to your password.

name: ci

on:
  push:
    branches: main

jobs:
  login:
    runs-on: ubuntu-latest
    steps:
      -
        name: Login to Docker Hub
        uses: docker/login-action@v2
        with:
          username: ${{ secrets.DOCKERHUB_USERNAME }}
          password: ${{ secrets.DOCKERHUB_TOKEN }}

GitHub Container Registry

To authenticate against the GitHub Container Registry, use the GITHUB_TOKEN for the best security and experience.

name: ci

on:
  push:
    branches: main

jobs:
  login:
    runs-on: ubuntu-latest
    steps:
      -
        name: Login to GitHub Container Registry
        uses: docker/login-action@v2
        with:
          registry: ghcr.io
          username: ${{ github.actor }}
          password: ${{ secrets.GITHUB_TOKEN }}

You may need to manage write and read access of GitHub Actions for repositories in the container settings.

You can also use a personal access token (PAT) with the appropriate scopes.

GitLab

name: ci

on:
  push:
    branches: main

jobs:
  login:
    runs-on: ubuntu-latest
    steps:
      -
        name: Login to GitLab
        uses: docker/login-action@v2
        with:
          registry: registry.gitlab.com
          username: ${{ secrets.GITLAB_USERNAME }}
          password: ${{ secrets.GITLAB_PASSWORD }}

If you have Two-Factor Authentication enabled, use a Personal Access Token instead of a password.

Azure Container Registry (ACR)

Create a service principal with access to your container registry through the Azure CLI and take note of the generated service principal's ID (also called client ID) and password (also called client secret).

name: ci

on:
  push:
    branches: main

jobs:
  login:
    runs-on: ubuntu-latest
    steps:
      -
        name: Login to ACR
        uses: docker/login-action@v2
        with:
          registry: <registry-name>.azurecr.io
          username: ${{ secrets.AZURE_CLIENT_ID }}
          password: ${{ secrets.AZURE_CLIENT_SECRET }}

Replace <registry-name> with the name of your registry.

Google Container Registry (GCR)

Google Artifact Registry is the evolution of Google Container Registry. As a fully-managed service with support for both container images and non-container artifacts. If you currently use Google Container Registry, use the information on this page to learn about transitioning to Google Artifact Registry.

You can use either workload identity federation based keyless authentication or service account based authentication.

Workload identity federation based authentication

Configure the workload identity federation for github actions in gcloud (for steps, refer here). In the steps, your service account should the ability to push to GCR. Then use google-github-actions/auth action for authentication using workload identity like below:

name: ci

on:
  push:
    branches: main

jobs:
  login:
    runs-on: ubuntu-latest
    steps:
    - id: 'auth'
      name: 'Authenticate to Google Cloud'
      uses: 'google-github-actions/auth@v0'
      with:
        token_format: 'access_token'
        workload_identity_provider: '<workload_identity_provider>'
        service_account: '<service_account>'

    - name: Login to GCR
      uses: docker/login-action@v2
      with:
        registry: gcr.io
        username: oauth2accesstoken
        password: ${{ steps.auth.outputs.access_token }}

Replace <workload_identity_provider> with configured workload identity provider. For steps to configure, refer here.

Replace <service_account> with configured service account in workload identity provider which has access to push to GCR

Service account based authentication

Use a service account with the ability to push to GCR and configure access control. Then create and download the JSON key for this service account and save content of .json file as a secret called GCR_JSON_KEY in your GitHub repo. Ensure you set the username to _json_key, or _json_key_base64 if you use a base64-encoded key.

name: ci

on:
  push:
    branches: main

jobs:
  login:
    runs-on: ubuntu-latest
    steps:
      -
        name: Login to GCR
        uses: docker/login-action@v2
        with:
          registry: gcr.io
          username: _json_key
          password: ${{ secrets.GCR_JSON_KEY }}

Google Artifact Registry (GAR)

You can use either workload identity federation based keyless authentication or service account based authentication.

Workload identity federation based authentication

Configure the workload identity federation for github actions in gcloud (for steps, refer here). In the steps, your service account should the ability to push to GAR. Then use google-github-actions/auth action for authentication using workload identity like below:

name: ci

on:
  push:
    branches: main

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

Replace <workload_identity_provider> with configured workload identity provider

Replace <service_account> with configured service account in workload identity provider which has access to push to GCR

Replace <location> with the regional or multi-regional location of the repository where the image is stored.

Service account based authentication

Use a service account with the ability to push to GAR and configure access control. Then create and download the JSON key for this service account and save content of .json file as a secret called GAR_JSON_KEY in your GitHub repo. Ensure you set the username to _json_key, or _json_key_base64 if you use a base64-encoded key.

name: ci

on:
  push:
    branches: main

jobs:
  login:
    runs-on: ubuntu-latest
    steps:
      -
        name: Login to GAR
        uses: docker/login-action@v2
        with:
          registry: <location>-docker.pkg.dev
          username: _json_key
          password: ${{ secrets.GAR_JSON_KEY }}

Replace <location> with the regional or multi-regional location of the repository where the image is stored.

AWS Elastic Container Registry (ECR)

Use an IAM user with the ability to push to ECR with AmazonEC2ContainerRegistryPowerUser managed policy for example. Then create and download access keys and save AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY as secrets in your GitHub repo.

name: ci

on:
  push:
    branches: main

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

If you need to log in to Amazon ECR registries associated with other accounts, you can use the AWS_ACCOUNT_IDS environment variable:

name: ci

on:
  push:
    branches: main

jobs:
  login:
    runs-on: ubuntu-latest
    steps:
      -
        name: Login to ECR
        uses: docker/login-action@v2
        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

Only available with AWS CLI version 1

You can also use the Configure AWS Credentials action in combination with this action:

name: ci

on:
  push:
    branches: main

jobs:
  login:
    runs-on: ubuntu-latest
    steps:
      -
        name: Configure AWS Credentials
        uses: aws-actions/configure-aws-credentials@v1
        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@v2
        with:
          registry: <aws-account-number>.dkr.ecr.<region>.amazonaws.com

Replace <aws-account-number> and <region> with their respective values.

AWS Public Elastic Container Registry (ECR)

Use an IAM user with the ability to push to ECR Public with AmazonElasticContainerRegistryPublicPowerUser managed policy for example. Then create and download access keys and save AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY as secrets in your GitHub repo.

name: ci

on:
  push:
    branches: main

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

Replace <region> with its respective value (default us-east-1).

OCI Oracle Cloud Infrastructure Registry (OCIR)

To push into OCIR in specific tenancy the username must be placed in format <tenancy>/<username> (in case of federated tenancy use the format <tenancy-namespace>/oracleidentitycloudservice/<username>).

For password create an auth token. Save username and token as a secrets in your GitHub repo.

name: ci

on:
  push:
    branches: main

jobs:
  login:
    runs-on: ubuntu-latest
    steps:
      -
        name: Login to OCIR
        uses: docker/login-action@v2
        with:
          registry: <region>.ocir.io
          username: ${{ secrets.OCI_USERNAME }}
          password: ${{ secrets.OCI_TOKEN }}

Replace <region> with their respective values from availability regions

Quay.io

Use a Robot account with the ability to push to a public/private Quay.io repository.

name: ci

on:
  push:
    branches: main

jobs:
  login:
    runs-on: ubuntu-latest
    steps:
      -
        name: Login to Quay.io
        uses: docker/login-action@v2
        with:
          registry: quay.io
          username: ${{ secrets.QUAY_USERNAME }}
          password: ${{ secrets.QUAY_ROBOT_TOKEN }}

Customizing

inputs

Following inputs can be used as step.with keys

Name Type Default Description
registry String Server address of Docker registry. If not set then will default to Docker Hub
username String Username used to log against the Docker registry
password String Password or personal access token used to log against the Docker registry
ecr String auto Specifies whether the given registry is ECR (auto, true or false)
logout Bool true Log out from the Docker registry at the end of a job

Keep up-to-date with GitHub Dependabot

Since Dependabot has native GitHub Actions support, to enable it on your GitHub repo all you need to do is add the .github/dependabot.yml file:

version: 2
updates:
  # Maintain dependencies for GitHub Actions
  - package-ecosystem: "github-actions"
    directory: "/"
    schedule:
      interval: "daily"

More Repositories

1

compose

Define and run multi-container applications with Docker
Go
32,049
star
2

awesome-compose

Awesome Docker Compose samples
HTML
29,388
star
3

kitematic

Visual Docker Container Management on Mac & Windows
JavaScript
12,254
star
4

labs

This is a collection of tutorials for learning how to use Docker with various tools. Contributions welcome.
PHP
11,433
star
5

docker-bench-security

The Docker Bench for Security is a script that checks for dozens of common best-practices around deploying Docker containers in production.
Shell
8,831
star
6

dockercraft

Docker + Minecraft = Dockercraft
Lua
7,057
star
7

docker-py

A Python library for the Docker Engine API
Python
6,638
star
8

machine

Machine management for a container-centric world
Go
6,617
star
9

docker-ce

⚠️ This repository is deprecated and will be archived (Docker CE itself is NOT deprecated) see the https://github.com/docker/docker-ce/blob/master/README.md ⚠️
Go
5,697
star
10

cli

The Docker CLI
Go
4,582
star
11

docs

Source repo for Docker's Documentation
Markdown
4,026
star
12

build-push-action

GitHub Action to build and push Docker images with Buildx
TypeScript
3,892
star
13

buildx

Docker CLI plugin for extended build capabilities with BuildKit
Go
3,220
star
14

genai-stack

Langchain + Docker + Neo4j + Ollama
Python
2,880
star
15

getting-started

Getting started with Docker
JavaScript
2,820
star
16

libchan

Like Go channels over the network
Go
2,471
star
17

for-mac

Bug reports for Docker Desktop for Mac
2,393
star
18

docker-install

Docker installation script
Shell
2,034
star
19

for-win

Bug reports for Docker Desktop for Windows
1,818
star
20

app

Make your Docker Compose applications reusable, and share them on Docker Hub
Go
1,571
star
21

roadmap

Welcome to the Public Roadmap for All Things Docker! We welcome your ideas.
1,445
star
22

compose-on-kubernetes

Deploy applications described in Compose onto Kubernetes clusters
Go
1,420
star
23

docker-credential-helpers

Programs to keep Docker login credentials safe by storing in platform keystores
Go
1,000
star
24

compose-cli

Easily run your Compose application to the cloud with compose-cli
Go
954
star
25

libkv

Distributed key/value store abstraction library
Go
850
star
26

setup-buildx-action

GitHub Action to set up Docker Buildx
TypeScript
839
star
27

metadata-action

GitHub Action to extract metadata (tags, labels) from Git reference and GitHub events for Docker
TypeScript
799
star
28

for-linux

Docker Engine for Linux
745
star
29

libcompose

*Unmaintained/Deprecated* An experimental go library providing Compose-like functionality
Go
584
star
30

setup-qemu-action

GitHub Action to install QEMU static binaries
TypeScript
377
star
31

community

327
star
32

go-plugins-helpers

Go helper packages to extend the Docker Engine
Go
320
star
33

hub-tool

🧪 Docker Hub experimental CLI tool
Go
311
star
34

welcome-to-docker

JavaScript
267
star
35

engine-api

DEPRECATED: Please see https://github.com/docker/docker/tree/master/client
Go
266
star
36

hub-feedback

Feedback and bug reports for the Docker Hub
231
star
37

doodle

A Home for Docker Doodles
Go
221
star
38

go-connections

Utility package to work with network connections
Go
204
star
39

scout-cli

Docker Scout CLI
Shell
203
star
40

go-units

Parse and print size and time units in human-readable format
Go
198
star
41

compose-switch

Go
196
star
42

go-docker

(Still WIP) Official Go SDK for Docker
Go
186
star
43

scan-cli-plugin

Docker Scan is a Command Line Interface to run vulnerability detection on your Dockerfiles and Docker images
Go
177
star
44

gordon

Cli application to manage github pull requests
Go
177
star
45

docker-ce-packaging

Packaging scripts for Docker CE
Makefile
171
star
46

github-actions

⚠️ This repository is deprecated and has been replaced by docker/build-push-action@v2
Go
163
star
47

bake-action

GitHub Action to use Docker Buildx Bake as a high-level build command
TypeScript
158
star
48

sbom-cli-plugin

Plugin for Docker CLI to support SBOM creation using Syft
Go
143
star
49

hacktoberfest-2022

Docker Hacktoberfest 2022
140
star
50

extensions-sdk

Desktop Extensions SDK
133
star
51

go-events

Composable event distribution for Go
Go
131
star
52

libtrust

Primitives for identity and authorization
Go
107
star
53

node-sdk

Docker CLI gRPC JavaScript SDK
JavaScript
106
star
54

compose-ecs

Deploy compose application on ECS
Go
99
star
55

golang-cross

Dockerfile
98
star
56

go-metrics

Package for metrics collection in Docker projects
Go
86
star
57

volumes-backup-extension

Back up, clone, restore, and share Docker volumes effortlessly.
PLpgSQL
77
star
58

desktop-linux

Bug reports for Docker Desktop for Linux
71
star
59

containerd-packaging

Linux distro packaging for containerd
Shell
64
star
60

opensource

Contains documentation and scripts related to the management of Open Source at Docker
Go
62
star
61

getting-started-app

A simple application for the getting started guide in Docker's documentation
JavaScript
62
star
62

dev-environments

59
star
63

multi-container-app

EJS
58
star
64

scout-action

Docker Scout GitHub Action
JavaScript
57
star
65

actions-toolkit

Toolkit for Docker (GitHub) Actions
TypeScript
46
star
66

extension-ideas

A place to suggest new ideas for Docker Extensions and get new ideas of what to build for the larger Docker community
45
star
67

binfmt

Please use https://github.com/linuxkit/linuxkit/tree/master/pkg/binfmt instead of this repo
Go
43
star
68

index-cli-plugin

Go
40
star
69

whalesay

A repository in support of the Docker's official whalesay image
Perl
38
star
70

dev-envs-extension

TypeScript
36
star
71

code-of-conduct

35
star
72

HttpOverStream

.NET library for using HTTP 1.1 over streams, especially Windows Named Pipes
C#
33
star
73

scout-demo-service

Dockerfile
26
star
74

get-involved

Get Involved with Docker
CSS
24
star
75

buildkit-syft-scanner

BuildKit Syft scanner
Go
21
star
76

packaging

Docker Packaging (apk, deb, rpm, static)
Dockerfile
19
star
77

go

Go packages with small patches autogenerated (used for canonical/json)
Go
18
star
78

cli-docs-tool

Utilities to generate (reference) documentation for the docker CLI
Go
18
star
79

base-cli-plugin

Experimental Docker CLI plugin to detect base images
Go
16
star
80

notary-official-images

Shell
16
star
81

go-imageinspect

Go
13
star
82

docker-ai

Docker AI is an extension for VSCode which provides runnable terminals inside of notebooks. Docker AI integrates AI recommendations to assist with debugging and improving your Docker projects.
13
star
83

python-docker

A simple Python app for the Python Language Guide in Docker's Docs
Python
11
star
84

babashka-pod-docker

Go
11
star
85

dc23-secure-workshop

DockerCon 2023 Secure Development with Docker hands-on exercises code
Dockerfile
10
star
86

import-restrictions

Restrict imports in your go project
Go
9
star
87

extensions-submissions

Submit your Docker Extension here
Shell
9
star
88

engine-sync

Sync moby/moby with docker/engine
Shell
8
star
89

docker-nodejs-sample

A simple Node.js application for the guide in Docker's documentation
JavaScript
7
star
90

docker-dotnet-sample

A simple .NET web application
HTML
7
star
91

python-docker-dev

A simple Python app for the Python Language Guide in Docker's Docs
Python
7
star
92

database-extension

TypeScript
6
star
93

buildx-desktop

6
star
94

github-actions-runner

Docker's containerized github-actions runner
Shell
6
star
95

desktop-action

Docker Desktop action
6
star
96

docker-php-sample

A simple PHP application
PHP
5
star
97

compose-desktop

3
star
98

cli-scan-feedback

Bug report for CLI Scanning
3
star
99

docker-spcs-demo

2
star
100

getting-started-todo-app

Sample application to get started with Docker
JavaScript
2
star