How to build more secure apps using multi-stage builds with a runtime base image
CGO_ENABLED=0
is added to the Dockerfile to ensure that the compiled binary is statically linked. CGO is a Go tool that enables the creation of Go packages that call C code. When CGO is disabled, the resulting binary is statically linked.
hello-minimus.go
.
This is a very simple script which prints “Hello from Minimus!” to the terminal. You can use your own script instead.
go.mod
file. This file declares the modules and dependencies required by the project. In our case, the module set is only needed for testing purposes, so it’s very simple.
Dockerfile
hello-minimus.go
go.mod
hello-go
:
.
specifies the current directory as the build context.CGO_ENABLED=1
flag. Make sure the required C libraries are available in both your build and runtime environments.
In the example below, we will use the Minimus Glibc-Dynamic image as a runtime base for a simple web application.
hello-minimus-web.go
and save it to your project directory. This is a very simple script that creates a webpage with several tabs so you can navigate between them.
go.mod
file. This file declares the modules and dependencies required by the project. In our case, the module set is only needed for testing purposes, so it’s very simple.
Dockerfile
hello-minimus-web.go
go.mod
.
specifies the current directory as the build context.