...

/

Updates to the Dockerfile Build Processes

Updates to the Dockerfile Build Processes

Learn how to update the Docker Compose file for microservices deployment.

We have only a single Dockerfile that builds the monolith. Going forward, we also need a way to compile the individual services. To accomplish this, we will use an additional Dockerfile that will make use of build arguments to target the right service to build.

The new Dockerfile will be named Dockerfile.microservices and live alongside the current one in /docker:

ARG svc
FROM golang:1.18-alpine AS builder
ARG svc
WORKDIR /mallbots
COPY go.* ./
RUN go mod download
COPY .. ./
RUN go build -ldflags="-s -w" -v -o service \
./${svc}/cmd/service
FROM alpine:3 AS runtime
COPY --from=builder /mallbots/docker/wait-for .
RUN chmod +x /wait-for
COPY --from=builder /mallbots/service /mallbots/service
CMD ["/mallbots/service"]
The new Dockerfile

This is a multi-stage Dockerfile. In our first stage called builder, we compile the service into a binary. In the second stage, we copy the wait-for utility, which is used to wait for the database to be available, and the newly compiled binary. By using this Dockerfile, we keep the containers we produce very small, which helps with transferring them and loading ...