dongsigan2044 2019-03-11 16:19
浏览 81
已采纳

“没有此类文件或目录”以及Docker暂存映像

Getting an error:

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

this error disappear when using alpine image.

this is my Dockerfile:

ARG PROJ_NS=gitlab.com/jonas.jasas
ARG PROJ_NAME=httprelay
ARG PROJ_BIN_PATH=/$PROJ_NAME

################################################################################
FROM golang:alpine
RUN apk update && apk add --no-cache git

ARG PROJ_NS
ARG PROJ_NAME
ARG PROJ_BIN_PATH

RUN go get -d $PROJ_NS/$PROJ_NAME/...
WORKDIR $GOPATH/src/$PROJ_NS/$PROJ_NAME
RUN go get -d ./cmd/...
RUN GOOS=linux GOARCH=amd64 go build -ldflags="-w -s" -o $PROJ_BIN_PATH ./cmd/...

RUN echo "nobody:x:65534:65534:Nobody:/:" > /etc_passwd

################################################################################
#FROM alpine
FROM scratch

ARG PROJ_BIN_PATH

COPY --from=0 /etc_passwd /etc/passwd
COPY --from=0 $PROJ_BIN_PATH /entrypoint

USER nobody

EXPOSE 8800
ENTRYPOINT ["/entrypoint"]
  • 写回答

1条回答 默认 最新

  • dsbiw2911188 2019-03-11 17:00
    关注

    Turn off CGO since that can result in dynamic links to libc/libmusl.

    RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build \
        -ldflags="-w -s" -o $PROJ_BIN_PATH ./cmd/...
    

    The no such file or directory error with a binary indicates either you did not call your binary by the right name, or that your binary is dynamically linked to a library that does not exist.

    You can check for dynamic links with ldd, e.g.:

    docker build --target=0 -t your_go_image .
    docker run -it --rm your_go_image ldd /$PROJ_NAME
    

    Here's an example with one of my own projects:

    $ go build -o test .
    
    $ ldd test
            linux-vdso.so.1 (0x00007ffd2ebd8000)
            libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007f2dda9ed000)
            libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f2dda64e000)
            /lib64/ld-linux-x86-64.so.2 (0x00007f2ddac0a000)
    
    $ CGO_ENABLED=0 go build -o test .                                                                                                     
    
    $ ldd test
            not a dynamic executable
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 如何删除这个虚拟音频
  • ¥50 hyper默认的default switch
  • ¥15 网站打不开,提示502 Bad Gateway
  • ¥20 基于MATLAB的绝热压缩空气储能系统代码咨询
  • ¥15 R语言建立随机森林模型出现的问题
  • ¥20 unity内置语言切换的按钮设置
  • ¥15 中级微观经济学,生产可能性边界问题
  • ¥15 TCP传输时不同网卡传输用时差异过大
  • ¥15 请各位看看我写的属于什么算法,或者有更正确的写法?
  • ¥15 html5 qrcode 扫描器