您的位置:首页 > 大数据 > 人工智能

自建镜像启动报:"no such file or directory"

2018-06-20 16:25 351 查看
工作中编写prometheus的vsphere vcenter的exporter之后,进行容器化部署的实践,就参照prometheus的Dockerfile写了一个

FROM        quay.io/prometheus/busybox:latest
LABEL maintainer "QHCloud Observer Exporter"
USER       root
EXPOSE     3871
COPY observer_vcenter_exporter /bin/observer_vcenter_exporter
#WORKDIR    /
ENTRYPOINT [ "/bin/observer_vcenter_exporter" ]
CMD        [ "--config-file=/etc/observer/vcenter.yml"]

但启动的时候报如下错误:

standard_init_linux.go:190: exec user process caused "no such file or directory"

经过不停的测试,发现是打出来的二进制文件在busybox中无法运行,但prometheus能运行,就通过阅读promu的源码并通过增加-v参数打印出了prometheus编译的参数

go build -o /home/chensl004/Workspace/go/src/github.com/prometheus/prometheus/prometheus -ldflags -X github.com/prometheus/prometheus/vendor/github.com/prometheus/common/version.Version=2.3.0.1 -X github.com/prometheus/prometheus/vendor/github.com/prometheus/common/version.Revision=3cf878f9079773ced3461ae3c4b2516e47c07264 -X github.com/prometheus/prometheus/vendor/github.com/prometheus/common/version.Branch=2.3.0 -X github.com/prometheus/prometheus/vendor/github.com/prometheus/common/version.BuildUser=chensl004@chensl004 -X github.com/prometheus/prometheus/vendor/github.com/prometheus/common/version.BuildDate=20180620-06:55:23  -extldflags '-static' -a -tags netgo github.com/prometheus/prometheus/cmd/prometheus

经过尝试发现增加-tags netgo之后镜像启动正常,在网上找了一下对go build -tags的描述比较少,依然不清楚为什么。后面发现网上有对比-tags netgo 和CGO_ENABLED,通过设置CGO_ENABLED=0环境变量,发现镜像启动也是没问题的。

个人猜测,golang默认使用cgo编译,但busybox中没有c相关的环境导致二进制文件无法正常运行。因此,将cgo编译关闭之后就没问题了。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
相关文章推荐