zoukankan      html  css  js  c++  java
  • 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
    



    P.S. 这种情况可以使用 ldd 获得依赖的动态库,将其 COPY 到相应的目录。

    Architecture 不一致

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

    docker build --platform=linux/arm ...
    
  • 相关阅读:
    Key and Certificate Conversion
    openssl
    python http通信实现
    鼠标右键添加cmd
    好文章
    wireshark里无网络接口解决办法
    python垃圾回收
    终于有人把 Docker 讲清楚了
    mongodb的监控与性能优化
    mongodb创建超级用户和普通用户(对应数据库的用户)
  • 原文地址:https://www.cnblogs.com/tiantiandas/p/go_running_error_in_docker.html
Copyright © 2011-2022 走看看