Project 2 โ€บ 04 Build your Docker image in CIGitHub โ†—
๐Ÿค– AI Prompt โ€” stuck? paste this

โ€œWrite a GitHub Actions job that builds my Docker image from the Dockerfile using docker/build-push-action without pushing it, tagged myapp:ci.โ€

04 โ€” Build your Docker image in CI

Category: Docker in CI ยท Priority: High ยท Step: 5

Reuse the Dockerfile from Project 1 โ€” build it on every push to catch broken images early.

๐ŸŽฏ What is this task?

In Project 1 you wrote a Dockerfile. Here you make CI build that image automatically, so a change that breaks the build is caught before anyone deploys it. You'll use Docker's official buildx action.

๐Ÿ”— Prerequisite: This builds on the Dockerfile you created in Project 1 โ€” Dockerize a Simple Web App.

๐Ÿค– AI Prompt

"Write a GitHub Actions job that builds my Docker image from the Dockerfile in the repo root using docker/build-push-action, without pushing it. Tag it myapp:ci."

๐Ÿ“‹ Step-by-step

Add a new job to .github/workflows/ci.yml:

  docker-build:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4

      - name: Set up Docker Buildx
        uses: docker/setup-buildx-action@v3

      - name: Build image (no push)
        uses: docker/build-push-action@v6
        with:
          context: .
          push: false
          tags: myapp:ci

push: false means "build only" โ€” we verify the image compiles without uploading it anywhere yet. (Pushing comes in the next lesson.)

โœ… Done when

  • A docker-build job appears in the Actions tab
  • The image builds successfully from your Dockerfile
  • Breaking the Dockerfile turns the job red

๐Ÿ“ Quiz

Answer all 2 questions correctly to complete this lesson.

1. What does `push: false` mean in build-push-action?
2. Why build the Docker image in CI at all?
โ† PreviousPass the quiz to completeNext โ†’