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 metadata提取的PDF元数据,如何转换为一个Excel
  • ¥15 关于arduino编程toCharArray()函数的使用
  • ¥100 vc++混合CEF采用CLR方式编译报错
  • ¥15 coze 的插件输入飞书多维表格 app_token 后一直显示错误,如何解决?
  • ¥15 vite+vue3+plyr播放本地public文件夹下视频无法加载
  • ¥15 c#逐行读取txt文本,但是每一行里面数据之间空格数量不同
  • ¥50 如何openEuler 22.03上安装配置drbd
  • ¥20 ING91680C BLE5.3 芯片怎么实现串口收发数据
  • ¥15 无线连接树莓派,无法执行update,如何解决?(相关搜索:软件下载)
  • ¥15 Windows11, backspace, enter, space键失灵