Cloud Native 5 min read

Integrating GitHub Actions CI/CD Workflow with Docker

This tutorial explains how to set up a GitHub Actions CI/CD pipeline for a Docker‑based project, covering workflow file creation, YAML configuration, secret management, and verification of Docker image builds.

DevOps Cloud Academy
DevOps Cloud Academy
DevOps Cloud Academy
Integrating GitHub Actions CI/CD Workflow with Docker

GitHub Actions is an automation tool for adding CI/CD workflows to projects hosted on GitHub; this guide focuses on integrating such workflows into Docker‑based projects.

The tutorial assumes you already understand Docker and have a project with a Dockerfile in its root, using a simple Python example that can be cloned from a GitHub repository.

1. Create the project and add a workflow file

Create a .github directory at the root of your project, then a workflows sub‑directory where the workflow YAML file will reside. For this example, create a single file named main.yml.

2. Write the pipeline

Insert the following content into main.yml:

name: Build and Publish Docker
on: [push]
jobs:
  build:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@master
      - name: Publish to Docker Repository
        uses: elgohr/Publish-Docker-Github-Action@master
        with:
          name: ispeakcode/docker-githubaction
          username: ${{ secrets.DOCKER_USERNAME }}
          password: ${{ secrets.DOCKER_PASSWORD }}

Each line serves a specific purpose: line 1: Sets the workflow name displayed in the Actions tab. line 2: Triggers the workflow on every push to the repository. lines 3–6: Define a job named build that runs on the latest Ubuntu runner; jobs consist of ordered steps. line 7: Checks out the repository source code using the official checkout action. lines 8–9: Use the Publish Docker action to build a Docker image and push it to Docker Hub, supplying the required parameters name, username, and password.

3. Add secrets

Because hard‑coding Docker credentials is insecure, store them as repository secrets. Navigate to /settings/secrets in your GitHub repository, create secrets named DOCKER_USERNAME and DOCKER_PASSWORD, and paste the appropriate values.

4. Check workflow execution and the image

After committing and pushing your code, the workflow runs automatically. Monitor its progress on the /actions page of the repository and verify the newly built image on Docker Hub via https://cloud.docker.com/repository/.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

ci/cdAutomationworkflowYAMLGitHub Actions
DevOps Cloud Academy
Written by

DevOps Cloud Academy

Exploring industry DevOps practices and technical expertise.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.