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.
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/.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
DevOps Cloud Academy
Exploring industry DevOps practices and technical expertise.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
