1 回答

TA貢獻2016條經驗 獲得超9個贊
關閉 CGO,因為這會導致到 libc/libmusl 的動態鏈接。
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build \
-ldflags="-w -s" -o $PROJ_BIN_PATH ./cmd/...
二進制文件的無此類文件或目錄錯誤表示您沒有使用正確的名稱調用二進制文件,或者您的二進制文件動態鏈接到不存在的庫。
您可以使用 來檢查動態鏈接ldd,例如:
docker build --target=0 -t your_go_image .
docker run -it --rm your_go_image ldd /$PROJ_NAME
這是我自己的項目之一的示例:
$ go build -o test .
$ ldd test
linux-vdso.so.1 (0x00007ffd2ebd8000)
libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007f2dda9ed000)
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f2dda64e000)
/lib64/ld-linux-x86-64.so.2 (0x00007f2ddac0a000)
$ CGO_ENABLED=0 go build -o test .
$ ldd test
not a dynamic executable
- 1 回答
- 0 關注
- 198 瀏覽
添加回答
舉報