I'm trying to build a go package with the following command:
CGO_ENABLED=0 GOOS=linux go build -o bin/router -installsuffix cgo -ldflags '-w'
This takes around 0.5 seconds on my pc. The same command in a docker container takes 45 seconds.
RUN CGO_ENABLED=0 GOOS=linux go build -o /app/router -installsuffix cgo -ldflags '-w' /build/src/global/router
Locally I have go version 1.12.9 linux/amd64. The docker container uses the golang:1.13 image as base.
My guess would be that the docker build process has less CPU available but does that make this big of a difference? What could be the cause for this issue?
This is reproducable with a minimal example:
main.go:
package main
import "log"
func main() {
log.Println("test")
}
Dockerfile:
FROM golang:1.13
ADD main.go .
RUN CGO_ENABLED=0 GOOS=linux go build -o main -installsuffix cgo -ldflags '-w'
CMD [ "main" ]
The command inside the docker container takes about 5 seconds compared to < 0.1 seconds on my pc.