During my summer internship, I learned about publishing a docker image to GitHub's Container Registry using GitHub Actions. I decided it would be a nice thing to share so i made a blog post .
Step 1: Create a new repository
For this tutorial, I'll be naming my repository “publish-to-gcr”. After we're done naming our repository, we're gonna want to make sure that our repository is public.
Step 2: Create a file
You can create any program with files of your choice, but for my example, I'll create an app.js
file. Inside of the app.js
file, I'll console.log the words, "Hello, world!"
Step 3: Create a Docker file
At the root of the project, I created a Docker file with the following contents.
FROM node:alpine
COPY . /app
WORKDIR /app
CMD node app.js
Step 4: Create an action
At the root of my project, I created a .github/workflows
folder. Inside of it, I created a file called publish.yml
. Inside of my publish.yml
, I wrote the following code (please note that you will need to replace some values such as the user name:
name: publish
on: [push]
jobs:
publish-hello-docker-image:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Login to GitHub Container Registry
uses: docker/login-action@v1
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build the hello-docker Docker image
run: |
docker build . --tag ghcr.io/deselikem/hello-docker-gcr-demo:latest
docker run ghcr.io/deselikem/hello-docker-gcr-demo:latest
docker push ghcr.io/deselikem/hello-docker-gcr-demo:latest
Step 5: Push and commit your changes to trigger the action
Head over to the Actions icon in your repository. You should see the action that we created using the text editor. If everything was done correctly, the actions should have been run and we can go check to see all the steps that the Action took to make sure that it's properly published.
Step 6: Check out your package that's been published on GitHub's container registry!
In your repo, if you scroll down, you will see a section highlighting the packages associated with your repository. It should the one you just made!
If you prefer video tutorials over blog tutorials, I created a video tutorial for you to follow. Check it out!