25% off

Use code FUNCMAIN at checkout for 25% off all premium courses.

Get started →

Multistage Dockerfiles For Your Go Apps!

March 12, 2023
Elliot Forbes

Elliot Forbes

Course Instructor

Hey Gophers! My name is Elliot and I'm the creator of TutorialEdge and I've been working with Go systems for roughly 5 years now.

In this video, we are going to be taking a look at how we can evolve our single stage dockerfile into a multistage dockerfile.

Finished Dockerfile:

FROM golang:latest AS builder
WORKDIR /app
COPY . .
RUN CGO_ENABLED=0 GOOS=linux go build -o main main.go

# Second stage of our application
FROM alpine:latest AS production
COPY --from=builder /app .

CMD ["./main"]

Commands in Video:

$ docker build -t multistage-go-app .
$ docker run -it -p 3000:3000 multistage-go-app
$ docker run -d 3000:3000 multistage-go-app

$ docker images | grep my-go-app
$ docker images | grep multistage-go-app