This guide explains a GitHub Actions workflow for building, testing, and preparing Docker images for publishing to Docker Hub.
In this guide, we’ll walk through a GitHub Actions workflow that builds a Docker image, validates it with runtime tests, and prepares it for publishing to Docker Hub.
Use the docker/build-push-action to build your image locally without pushing it immediately. This allows you to run integration or health checks before publishing.
After building the image, verify that the application starts and responds to its health endpoint. Replace placeholders with your actual GitHub Secrets or repository variables.
Copy
Ask AI
- name: Docker Image Testing run: | # List built images docker images # Run the container in detached mode docker run --name solar-system-app -d \ -p 3000:3000 \ -e MONGO_URI=$MONGO_URI \ -e MONGO_USERNAME=$MONGO_USERNAME \ -e MONGO_PASSWORD=$MONGO_PASSWORD \ ${{ vars.DOCKERHUB_USERNAME }}/solar-system:${{ github.sha }} # Display container IP address echo "Container IP:" $(docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' solar-system-app) # Test the /live endpoint echo "Testing /live endpoint" wget -q -O - http://127.0.0.1:3000/live | grep live
Ensure that your application exposes health endpoints like /live or /ready to prevent false positives during automated testing.
With your image successfully built and validated, you’re now ready to push it to Docker Hub. Continue to the next article to configure the push step in your workflow.