QGB / gohs

go http server url eval system cmd
MIT License
1 stars 1 forks source link

bash: ./gohs : No such file or directory #1

Open QGB opened 3 years ago

QGB commented 3 years ago
alpine build :
In [20]: !~/go/gohs/gohs
/bin/bash: /home/qgb/go/gohs/gohs: No such file or directory

In [21]: !file ~/go/gohs/gohs
/home/qgb/go/gohs/gohs: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib/ld-musl-x86_64.so.1, not stripped

ubuntu build:
In [23]: !md5sum ~/go/gohs/gohs
378be4102fbb3b2fbff9c6e6973c95da  /home/qgb/go/gohs/gohs

In [24]: !file ~/go/gohs/gohs
/home/qgb/go/gohs/gohs: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, not stripped

In [25]: !~/go/gohs/gohs
HTTP Server eval_cmd listening at :3000
panic: listen tcp :3000: bind: address already in use

goroutine 1 [running]:
main.main()
        /root/go/gohs/hs.go:46 +0x268
QGB commented 3 years ago

常见原因:该二进制文件是使用动态链接方式编译了一个使用了 GLIBC 库的程序生成的,但是 alpne 镜像中没有 GLIBC 库而是用的 MUSL LIBC 库,这样就会导致该二进制文件无法被执行。

解决办法:下面两个解决方法

改为静态编译 如果要使用动态链接函数编译的话,不要依赖 GLIBC (比如编译 Go 程序的时候指定 CGO_ENABLED=0 ) 或者在 alpine 中编译一个依赖 MUSL LIBC 的版本