Updates to the Dockerfile Build Processes
Learn how to update the Docker Compose file for microservices deployment.
We'll cover the following...
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 svcFROM golang:1.18-alpine AS builderARG svcWORKDIR /mallbotsCOPY go.* ./RUN go mod downloadCOPY .. ./RUN go build -ldflags="-s -w" -v -o service \./${svc}/cmd/serviceFROM alpine:3 AS runtimeCOPY --from=builder /mallbots/docker/wait-for .RUN chmod +x /wait-forCOPY --from=builder /mallbots/service /mallbots/serviceCMD ["/mallbots/service"]
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 ...