Search code examples
dockergoalpine-linux

How to build a go executable that doesn't link to musl libc


So:

The official Go build container is based on Alpine.

Alpine uses musl as libc instead of glibc.

I need to build a Go executable in a container that can be run on Ubuntu, which uses glibc.

How do I either

  1. Make the official GoLang build container use glibc or
  2. Build my GoLang project on an Ubuntu based container

I can't use the Disable CGO solution, as my Go code is a FUSE driver, which requires CGO


Solution

  • The golang:latest image is based on debian bullseye. You don't need anything else than using this image to build your binary so that it can be run as is on ubuntu.

    Just start your dockerfile with this line instead of what you're currently using.

    FROM golang:latest