How long should the containers take to

How long should the containers take to build during local development? I'm using one of the basic go examples and the built step takes ~1 minute. Is this normal?
=> [build 6/6] RUN CGO_ENABLED=0 GOOS=linux go build -o /server 53.4s
=> [build 6/6] RUN CGO_ENABLED=0 GOOS=linux go build -o /server 53.4s
2 Replies
Wonky Onion
Wonky Onion2mo ago
that seems normal to me for a first run, the layers should be cached for subsequent builds and quite a lot faster.
Josh
JoshOP2mo ago
It looks like the docker file from the template doesn't seem to be caching the build layer properly for me. I found this article on how to setup the go build cache: https://dev.to/jacktt/20x-faster-golang-docker-builds-289n And updated the docker file build step to:
ENV GOCACHE=/root/.cache/go-build
RUN --mount=type=cache,target="/root/.cache/go-build" CGO_ENABLED=0 GOOS=linux go build -o /server
ENV GOCACHE=/root/.cache/go-build
RUN --mount=type=cache,target="/root/.cache/go-build" CGO_ENABLED=0 GOOS=linux go build -o /server
Now on refresh the container rebuilds in just a couple seconds.
DEV Community
20X Faster Golang Docker Builds
According to the Go command documentation: "The go command caches build outputs for reuse in future...

Did you find this page helpful?