Run Go Binary Inside Alpine Image

Oct 19, 2024

Phenomenon

/app # ./ngapost2md --help
/bin/sh: ./ngapost2md: not found

Identify The Issue

/app # ldd ngapost2md
        /lib64/ld-linux-x86-64.so.2 (0x7f010de40000)
Error loading shared library libresolv.so.2: No such file or directory (needed by ngapost2md)
        libpthread.so.0 => /lib64/ld-linux-x86-64.so.2 (0x7f010de40000)
        libc.so.6 => /lib64/ld-linux-x86-64.so.2 (0x7f010de40000)

ldd - print shared object dependencies

It seems like libresolv is missing, which is included by gcompat and should be added to Dockerfile:

RUN apk add gcompat

Avoid The Issue

Build go binary with CGO_ENABLED=0 can possibly avoid this issue.


[back]