← Workflows

阅读中文版本

Docker Image Build Workflow

Build a Docker image from a Dockerfile, tag it, and verify it runs correctly before pushing to a registry.

beginner~20 mindockerimageworkflow

Objective

Build and verify a Docker image locally before sharing it with the team or pushing to a registry.

Environment

  • Docker installed and running
  • A Dockerfile in the project root
  • A .dockerignore file for exclusions

Steps

1. Build the image

Run docker build -t myapp:latest . to build the image from the Dockerfile.

Expected state: The image is built and tagged as myapp:latest.

2. Run the image

Run docker run -p 8080:8080 myapp:latest and verify the application responds.

Expected state: The container starts and the application is accessible.

3. Check image size

Run docker images myapp:latest to check the image size against the team budget.

Expected state: The image size is within the acceptable range.

Decision points

Which base image to use?

  • alpine for minimal size
  • debian for compatibility

Use alpine for production; debian if you need full glibc compatibility.

Expected outcome

A verified Docker image is available locally, ready to be pushed to a registry.

Verification

Run the container and curl the health endpoint to confirm the application is responding correctly.

Cleanup

Remove the image with docker rmi myapp:latest if not needed.

Build, tag, verify

Always run the image locally before pushing. A successful build does not guarantee a working application.

docker build -t myapp:latest .
docker run -p 8080:8080 myapp:latest
curl localhost:8080/health

Implementation Notes

This workflow provides a structured approach to ensure consistent results across team members and environments.

Common Pitfalls

Skipping verification steps or rushing through the process can lead to incomplete results. Always follow each step in order and verify before proceeding.