
Optimising Docker Builds for Go
This article describes how to improve build time for Docker containers with Go applications. It focuses on speeding up the build process rather than building images from scratch. It's updated(2026) version of my old medium article from 2023 Problem to Solve Let's start with an issue definition: Building a Go app on a laptop is quick, but building the same app inside Docker takes ages. Why is building an app on a local machine fast? Golang produces a binary file. Do you remember C? C also produces a binary file. Let's recap how we could compile a program in C. I promise, we will get back to Go soon. Let's consider the simplified Makefile below: CFLAGS := -Wall -Werror .default : app .PHONY : app # Let's cheat a bit and hardcode main.o, foo.o and bar.o app : foo.o bar.o main.o # link object files ${ CC } -o app $^ # Build ${name}.o based on ${name}.c %.o : %.c @ echo building $@ ${ CC } ${ CFLAGS } -c $< # Remove object files and binary clean : rm -vf * .o app Running make app will build
Continue reading on Dev.to
Opens in a new tab




