Skip to main content
In this tutorial, we’ll enhance our GitHub Actions workflow to build, test, and publish a Docker image to Docker Hub. You’ll learn how to use Docker Buildx for multi-platform builds, run live container tests, and manage credentials securely for a robust CI/CD pipeline.

1. Build and Test the Docker Image

First, we compile the image locally without pushing it, then spin up a container to validate the /live endpoint.
Tagging images with the Git SHA ensures traceability. Use ${{ github.sha }} for an immutable reference.

2. Push the Docker Image to Docker Hub

Once tests pass, rebuild (with cache reuse) and push the image in a dedicated job.
Ensure your DOCKERHUB_TOKEN is stored as a GitHub repository secret to prevent credential leaks.

3. Inspecting the Workflow Logs

During the push step, the logs will indicate cache reuse and the push command:
The build-push-action automatically leverages layers from the testing job to speed up the push.

4. Verifying on Docker Hub

After completion, navigate to your Docker Hub repository. You should find a new tag matching the commit SHA, for example:
This confirms that your GitHub Actions workflow has successfully built, tested, and published your image.

Job Summary

Watch Video