How to publish Docker image in GitHub

GitHub actions are really cool, but, with GitHub repositories is better. Pushing a Docker image is very easy to setup. We need only a developer token from the GitHub’s profile and few lines in actions.

Get the GitHub Token

Connected to GitHub? Go to and click on Generate a new token. Select write:packages scope to be able to push the Docker image.

Use GitHub Action

Create a file in the repository .github/workflows/ci.yml and then paste this code in it:

name: publish

on: [push]

    runs-on: ubuntu-latest

    - uses: actions/checkout@v2

    - name: Login to GitHub Container Registry
      uses: docker/login-action@v1
        username: ${{ }}
        password: ${{ secrets.TOKEN }}

    - name: Build the Docker image
      run: |
        docker build . --tag
        docker run
        docker push

When it’s done ✅ 📦 , the package will appear in packages tab:

To be able to pull the image, docker agent must login in using GitHub Token, just save the token in .bashrc/.zshrc and run this command:

echo $CR_PAT | docker login -u yourname --password-stdin

Then, you can pull the image and run it 🐳

You Might Also Like

Leave a Reply