说明: <u>本文报错发生在和 GO 相关的实践中</u> <br>
Reference:
- [reddit]
 - [stackExchange]
 - [docker forums] <br><br>
 
可能原因
- CRLF 与 LF 差异
 - CGO 影响
 - architecture 不一致 <br><br>
 
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>
...
<br><br>
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
<br><br>
P.S. 这种情况可以使用 ldd 获得依赖的动态库,将其 COPY 到相应的目录。
Architecture 不一致
如果是在 amd 上 build image, 在 arm 上运行, 也会引发错误.
docker build --platform=linux/arm ...
 
                    版权声明:程序员胖胖胖虎阿 发表于 2022年9月21日 下午2:00。
转载请注明:Docker: Exec user process caused "no such file or directory" | 胖虎的工具箱-编程导航
                    
            转载请注明:Docker: Exec user process caused "no such file or directory" | 胖虎的工具箱-编程导航
相关文章
暂无评论...
