A Dockerfile is a text-based build specification that defines how to create a Docker image for a service. In a microservice test stack, each service gets its own Dockerfile so Docker Compose or test containers can build and run the required services. section 7.4.1 section 8.1.1
A practical Go Dockerfile uses a multistage build. A Go parent image compiles the service, then a scratch image receives only the generated executable. This separates compile-time dependencies from runtime contents and produces a smaller runtime image. section 7.4.5 section 8.1.1
Order service image
Use golang:1.18 as the builder, copy the service source into /usr/src/app, compile a Linux order executable with CGO disabled, copy it into scratch, and start it with CMD ["./order"]. A Payment service follows the same structure with a payment executable. Docker Compose can then build each service and provide ports, database URLs, and service endpoints through environment variables. section 7.4.6 section 7.4.5
FROM golang:1.18 AS builder #1 WORKDIR /usr/src/app COPY . . #2 RUN CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -o order ./cmd/main.go #3 FROM scratch COPY --from=builder /usr/src/app/order ./order #4 CMD ["./order"] #5
Inspect the complete multistage Dockerfile for the Order service, including the builder stage, artifact transfer, and runtime command. section 8.1.1
Build an image by preparing the Dockerfile and running docker build -t order . from the service directory. The directory becomes the build context. Tag and push the resulting image to a registry when a Kubernetes cluster must pull it; local development may instead copy images directly to cluster nodes. section 8.1.1

















