Hello everyone, today I’ll try to explain how to create multi-stage Docker builds in order to decrease build size with Dockerfile on a small Go application and the latest GoLang image from DockerHub.

Through this tutorial I won’t publish any code snippets directly, I’ll instead give you a repo to copy and paste.

First, we’ll create a really basic Go webserver using the Mux package. “Package gorilla/mux implements a request router and dispatcher for matching incoming requests to their respective handler." from their GitHub page. You can also learn how to install that package on your local from the link.

After that, we need to create a main.go file with the following content.

#docker

Multi-stage Builds, Docker Image Size Reduction
1.15 GEEK