The following multi-stage Dockerfile is similar to the usual way of containerizing Go applications. C libraries are required to interact with SQLite, therefore CGO must be enabled. Previously, I was using an alpine image instead of debian:buster-slim. Running with CGO enabled flag developed new issues. Once the app was built, required many directories which were missing in the Alpine image. Instead of detecting missing packages, I went with the debian:buster-slim solution. The compressed image size is around 35MB. The downside here is, we have unused folders/libraries in the debian image. Which means the image could be smaller.
While writing this story, I’ve found another blog called 7thzero, they’ve bumped into the same problem. Turns out the build command required additional -ldflags. I updated my build command. The advantage here is, now I can build from scratch (completely empty image). The compressed image size is around 9MB. 😏
More Stories like this
GitHub – droppyjs/droppy: Self-hosted file storage
Jest VSCode Extension | How to code Tutorial.
Import SVGs as React Components | How to code Tutorial