Your Web News in One Place

Help Webnuz

Referal links:

Sign up for GreenGeeks web hosting
August 10, 2022 05:20 pm GMT

How to Publish a Docker Image to GitHub's Container Registry

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.

Image description

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!"

Image description

Step 3: Create a Docker file

At the root of the project, I created a Docker file with the following contents.

FROM node:alpineCOPY . /appWORKDIR /appCMD node app.js

Image description

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: publishon: [push]jobs:publish-hello-docker-image:runs-on: ubuntu-lateststeps:- uses: actions/checkout@v2- name: Login to GitHub Container Registryuses: docker/login-action@v1with:registry: ghcr.iousername: ${{ github.actor }}password: ${{ secrets.GITHUB_TOKEN }}- name: Build the hello-docker Docker imagerun: |       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.

Image description

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!

Image description

Image description

If you prefer video tutorials over blog tutorials, I created a video tutorial for you to follow. Check it out!


Original Link: https://dev.to/github/publishing-a-docker-image-to-githubs-container-repository-4n50

Share this article:    Share on Facebook
View Full Article

Dev To

An online community for sharing and discovering great ideas, having debates, and making friends

More About this Source Visit Dev To