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

“没有此类文件或目录”以及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 MICE包多重插补后数据集汇总导出
    • ¥15 一道算法分析问题(关于3-MSAT)
    • ¥15 C++ FLUENT 化学反应速率 编写困难
    • ¥15 Python嵌套交叉验证
    • ¥15 linuxkit+elasticsearch
    • ¥15 兄得萌6.13do题😭😭大一小东西的work
    • ¥15 投不到原始数据,gdal投影代码
    • ¥20 卷积混响的代码帮写。。
    • ¥88 借助代码处理雷达影像,识别任意区域洪水前后的被淹没区域,并可视化展示。
    • ¥100 提问关于声学两个频率合成后主观听觉问题