diff --git a/docs/2022-06-08-dockerfile-go.html b/docs/2022-06-08-dockerfile-go.html index 040c6f3..a17c58f 100644 --- a/docs/2022-06-08-dockerfile-go.html +++ b/docs/2022-06-08-dockerfile-go.html @@ -1,7 +1,7 @@ -Index

Dockerfile for Go

Each time I start a new Go project, I repeat many steps.
Like set up .gitignore, CI configs, Dockerfile, ...

So I decide to have a baseline Dockerfile like this:

FROM golang:1.18-bullseye as builder
+Index

Dockerfile for Go

Each time I start a new Go project, I repeat many steps.
Like set up .gitignore, CI configs, Dockerfile, ...

So I decide to have a baseline Dockerfile like this:

FROM golang:1.19-bullseye as builder
 
-RUN go install golang.org/dl/go1.18@latest \
-    && go1.18 download
+RUN go install golang.org/dl/go1.19@latest \
+    && go1.19 download
 
 WORKDIR /build
 
@@ -17,9 +17,9 @@ FROM gcr.io/distroless/base-debian11
 COPY --from=builder /build/app /app
 
 ENTRYPOINT ["/app"]
-

I use multi-stage build to keep my image size small.
First stage is Go official image,
second stage is Distroless.

Before Distroless, I use Alpine official image,
There is a whole discussion on the Internet to choose which is the best base image for Go.
After reading some blogs, I discover Distroless as a small and secure base image.
So I stick with it for a while.

Also, remember to match Distroless Debian version with Go official image Debian version.

FROM golang:1.18-bullseye as builder
-

This is Go image I use as a build stage.
This can be official Go image or custom image is required in some companies.

RUN go install golang.org/dl/go1.18@latest \
-    && go1.18 download
+

I use multi-stage build to keep my image size small.
First stage is Go official image,
second stage is Distroless.

Before Distroless, I use Alpine official image,
There is a whole discussion on the Internet to choose which is the best base image for Go.
After reading some blogs, I discover Distroless as a small and secure base image.
So I stick with it for a while.

Also, remember to match Distroless Debian version with Go official image Debian version.

FROM golang:1.19-bullseye as builder
+

This is Go image I use as a build stage.
This can be official Go image or custom image is required in some companies.

RUN go install golang.org/dl/go1.19@latest \
+    && go1.19 download
 

This is optional.
In my case, my company is slow to update Go image so I use this trick to install latest Go version.

WORKDIR /build
 
 COPY go.mod .
diff --git a/posts/2022-06-08-dockerfile-go.md b/posts/2022-06-08-dockerfile-go.md
index 9f04bfe..b8fe99e 100644
--- a/posts/2022-06-08-dockerfile-go.md
+++ b/posts/2022-06-08-dockerfile-go.md
@@ -6,10 +6,10 @@ Like set up `.gitignore`, CI configs, Dockerfile, ...
 So I decide to have a baseline Dockerfile like this:
 
 ```Dockerfile
-FROM golang:1.18-bullseye as builder
+FROM golang:1.19-bullseye as builder
 
-RUN go install golang.org/dl/go1.18@latest \
-    && go1.18 download
+RUN go install golang.org/dl/go1.19@latest \
+    && go1.19 download
 
 WORKDIR /build
 
@@ -39,15 +39,15 @@ So I stick with it for a while.
 Also, remember to match Distroless Debian version with Go official image Debian version.
 
 ```Dockerfile
-FROM golang:1.18-bullseye as builder
+FROM golang:1.19-bullseye as builder
 ```
 
 This is Go image I use as a build stage.
 This can be official Go image or custom image is required in some companies.
 
 ```Dockerfile
-RUN go install golang.org/dl/go1.18@latest \
-    && go1.18 download
+RUN go install golang.org/dl/go1.19@latest \
+    && go1.19 download
 ```
 
 This is optional.