Home >Backend Development >Golang >Why Can't My Custom Go Binary Run in an Alpine Docker Image?

Why Can't My Custom Go Binary Run in an Alpine Docker Image?

Susan Sarandon
Susan SarandonOriginal
2024-12-05 22:43:09225browse

Why Can't My Custom Go Binary Run in an Alpine Docker Image?

Installed Go Binary Not Found in Path on Alpine Linux Docker

This question arises when attempting to run a custom Go binary on an Alpine Docker image, where the binary fails to be found in the path. While Alpine's default Go binary works as expected, custom binaries encounter the "not found" error.

The issue stems from a missing compatibility link in Alpine Linux. The binary relies on a specific dynamic library (e.g., /lib64/ld-linux-x86-64.so.2), but Alpine doesn't have a direct symlink to that library.

To resolve this issue, execute the following command within the Dockerfile:

RUN mkdir /lib64 && ln -s /lib/libc.musl-x86_64.so.1 /lib64/ld-linux-x86-64.so.2

This command creates the necessary symlink between compatible dynamic libraries, allowing the custom Go binary to find the required dependencies and execute successfully.

The above is the detailed content of Why Can't My Custom Go Binary Run in an Alpine Docker Image?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn