Building and packaging images
In the previous section, we learned about Docker images and how to look at the state of a running container; we also looked at how Docker images are stored locally. In this section, we will look at how to create our own Docker image by writing a Dockerfile
.
We will look at building the sample application inside the chapter13/embed
folder. The sample application is the same one we discussed in Chapter 4, Serving and Embedding HTML Content. The application will run an HTTP server listening on port 3333
to serve an embedded HTML page.
The Dockerfile
that we will use to build the Docker image looks as follows:
# 1. Compile the app. FROM golang:1.18 as builder WORKDIR /app COPY . . RUN CGO_ENABLED=0 GOOS=linux go build -a -o bin/embed # 2. Create final environment for the compiled binary. FROM alpine:latest RUN apk --update upgrade && apk --no-cache add curl ca-certificates && rm -rf /var/cache/apk/* RUN mkdir -p /app # 3...