Let’s publish a docker image to Docker Hub using a GitHub Action

I hope you already know GitHub is where you can put your git repositories likewise docker hub is where you can put your docker images. A Docker image is a file, comprised of multiple layers, that is used to execute code in a Docker container.

Prerequisites

  • You must have a application 🤭
  • You must have a docker hub account and docker hub repository
  • Your GitHub repository should contain a Dockerfile

Note: — Your application language doesn't matter write a dockerfile correclty

Step 1 — Click on Actions Tab on your GitHub repository

Step 2 — Click on new workflow to create a new one

Step 3 — Choose your workflow template

Your repository is contain a Dockerfile so GitHub will suggest you Docker template.

Now click on set up this workflow

Step 4 — Change workflow file like below

Now your workflow is ready. Before your commit this yaml file. Open your GitHub repository in a new tab in your browser.

Step 5 — Add your DockerHub Secrets to GitHub

Go to Settings section

Then select secrets

Click on new secrets to add your secrets

Now you need to add your docker username and password as github secrets which are going to use in GitHub action.

Once you added username and password, you can see GitHub secrets section like this

Now come back to previous browser tab and commit your GitHub action.

Also you can see your docker image in docker hub repository

Thank you guys! Hope you enjoy the article. You can find this GitHub repository and DockerHub repository in below

GitHub Repo

DockerHub Repo

Also don’t forgot to follow me on GitHub => Shehanka

--

--

Chamod Shehanka Perera
Platformer — A WSO2 Company

Software Engineer | GitHub Field Expert | Golang Sri Lanka Lead | GDG Organizer | KCD Sri Lanka Organizer| Beginner Surfer