Skip to main content

7. Connecting DockerHub to GitHub

danger

Never hardcode your passwords or tokens inside your GitHub Actions pipeline files (.yml). They must be securely stored in GitHub Secrets!

Generating a Personal Access Token (PAT)

We need a Personal Access Token (PAT) from DockerHub along with our username to allow the pipeline to authenticate and push to the Docker repository.

  1. In DockerHub, go to Account Settings -> Security. Account Settings

  2. Click on New Access Token. New Token

  3. Give it a descriptive name (like github-actions-push) and create it. Create Token

This will generate a secure Docker repository token that looks something like this: Generated Token

Configuring GitHub Secrets

Now, take this token and put it in GitHub Secrets so your pipeline can securely inject it during the build process.

  1. Go to your GitHub repository -> Settings -> Secrets and variables -> Actions. GitHub Settings

  2. Click on New repository secret. New Secret Button

  3. Create the following two secrets identically as shown: Create Secret Name Create Secret Value

Required Secrets Table

Secret KeyValue
DOCKERHUB_USERNAMEhashcodes7 (Your Username)
DOCKERHUB_TOKENYour DockerHub PAT

Next time you push code to GitHub, your CI/CD pipeline will utilize these secrets to authenticate.

Once your CI/CD pipeline finishes processing, you will get an automatically built and pushed image appearing right in DockerHub like this! Pipeline Success