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
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥100 房产抖音小程序苹果搜不到安卓可以付费悬赏
  • ¥15 STM32串口接收问题
  • ¥15 腾讯IOA系统怎么在文件夹里修改办公网络的连接
  • ¥15 filenotfounderror:文件是存在的,权限也给了,但还一直报错
  • ¥15 MATLAB和mosek的求解问题
  • ¥20 修改中兴光猫sn的时候提示失败
  • ¥15 java大作业爬取网页
  • ¥15 怎么获取欧易的btc永续合约和交割合约的5m级的历史数据用来回测套利策略?
  • ¥15 有没有办法利用libusb读取usb设备数据
  • ¥15 为什么openeluer里面按不了python3呢?