CGO项目Docker镜像运行报错standard_init_linux.go:228求助
CGO Go服务在Alpine Docker镜像中启动报错
核心报错:standard_init_linux.go:228: exec user process caused: no such file or directory
已排除的原因
- 非入口脚本存在CR换行导致
- 因项目依赖CGO,无法通过设置
CGO_ENABLED=0编译解决
环境与项目信息
- C库安装路径:
/usr/local/lib/sgp4/Linux/IFORT和/usr/local/lib/sgp4/Linux/GFORTRAN,包含多个.so文件 - 已尝试设置环境变量
LD_LIBRARY_PATH=/usr/local/sgp4/lib/Linux/IFORT - 项目包含一组wrapper .h文件及对应CGO注释(截图:
) - 二进制文件在Debian系统编译,必须运行在Alpine 3.17镜像中,编译阶段曾遇到
librt.so.1缺失问题
当前Dockerfile配置
FROM [redacted]/alpine-base:3.17 RUN apk update && \ apk add curl jq COPY etc/cfg/propagator.properties /usr/local/[redacted]/etc/cfg/ COPY bin/sgp4 /usr/local/[redacted]/bin/sgp4 COPY propagator/wrappers /usr/local/[redacted]/bin/wrappers # Download library files RUN mkdir -p /usr/local/sgp4/lib RUN curl --output /usr/local/sgp4/lib/SGP4.tar [redacted]/SGP4.tar RUN tar -xf /usr/local/sgp4/lib/SGP4.tar -C /usr/local/sgp4/lib RUN rm /usr/local/sgp4/lib/SGP4.tar RUN export LD_LIBRARY_PATH=/usr/local/sgp4/lib/Linux/IFORT RUN chmod a+rx /usr/local/[redacted]/bin/sgp4 RUN addgroup [redacted] && adduser -D -H -G [redacted] [redacted] USER [redacted]:[redacted] HEALTHCHECK NONE ENTRYPOINT ["/usr/local/[redacted]/bin/sgp4", "-config-file-path=/usr/local/[redacted]/etc/cfg/propagator.properties"]
已尝试的无效操作
曾怀疑库文件存在CR换行,添加以下命令无效果:
RUN for filey in $(find /usr/local/sgp4/lib/Linux -type f); do echo $filey; sed -i 's/\r$//g' $filey; done
RUN for filey in $(find /usr/local/sgp4/lib/Linux -type f); do echo $filey; tr -d \r < $filey > tmp.so; mv tmp.so $filey; done
内容的提问来源于stack exchange,提问作者robbieperry22
相关产品推荐
相关产品推荐

