Docker: Exec user process caused "no such file or directory"

时间:2019-11-06
本文章向大家介绍Docker: Exec user process caused "no such file or directory",主要包括Docker: Exec user process caused "no such file or directory"使用实例、应用技巧、基本知识点总结和需要注意事项,具有一定的参考价值,需要的朋友可以参考一下。

说明: 本文报错发生在和 GO 相关的实践中

Reference:

可能原因

  • CRLF 与 LF 差异
  • CGO 影响
  • architecture 不一致


CRLF 与 LF 差异

FROM golang
COPY . /srv
RUN apt-get update \
    && apt-get -y install --no-install-recommends dos2unix \
    && rm -rf /var/lib/apt/lists/* 
RUN dos2unix  /srv/<file_need_to_convert>
...



CGO 影响

  • CGO_ENABLED =1 : 开启, 编译时, 不会将动态库编译到 binary 中, 在docker multi-stage build 中, 会引发错误. ([reddit])
FROM golang AS builder 

RUN go get -u github.com/golang/dep/cmd/dep
RUN go get github.com/classzz/classzz \
    && cd /go/src/github.com/classzz/classzz \
    && dep ensure \
    && CGO_ENABLED=0 go install .\
    && CGO_ENABLED=0 go install ./cmd/czzctl 

FROM scratch
WORKDIR /app/

VOLUME ["/data"]
EXPOSE 8333 8334
ENTRYPOINT ["/app/classzz", "-b", "/data"]
COPY --from=builder /go/bin/classzz /app/classzz
COPY --from=builder /go/bin/czzctl /app/czzctl
COPY --from=builder /go/src/github.com/classzz/classzz/csatable.bin /app/csatable.bin



Architecture 不一致

如果是在 amd 上 build image, 在 arm 上运行, 也会引发错误.

docker build --platform=linux/arm ...

原文地址:https://www.cnblogs.com/tiantiandas/p/go_running_error_in_docker.html