douer9399 2018-11-03 07:01
浏览 829
已采纳

“ exec:\” go \”:在$ PATH中找不到可执行文件”

I have created dockerfile, successfully built it, but when I run it

sudo docker run -d -it -p 15555:9888 --name=docker-golang-test goTestDocker go run main.go host=0.0.0.0

it returns an error

docker: Error response from daemon: OCI runtime create failed: container_linux.go:348: starting container process caused "exec: \"go\": executable file not found in $PATH": unknown.

This is my Docker file

FROM golang:1.10.2-alpine3.7 AS build 
RUN apk --no-cache add gcc g++ make ca-certificates
WORKDIR /home/user/Desktop/work/go-work/GoProject/project
RUN ls
RUN pwd
COPY . .
RUN pwd
RUN apk update -qq && apk add git
RUN go get github.com/golang/protobuf/jsonpb
RUN go get github.com/golang/protobuf/proto
FROM alpine:3.7
WORKDIR /usr/bin
COPY --from=build /go/bin .
EXPOSE 9888
CMD ["./app"] --v
  • 写回答

1条回答 默认 最新

  • douningchang3610 2018-11-03 07:14
    关注
    FROM golang:1.10.2-alpine3.7 AS build 
    RUN apk --no-cache add gcc g++ make ca-certificates
    WORKDIR /go/src/github.com/{$whoami}/testProject
    RUN ls
    RUN pwd
    COPY . .
    RUN pwd
    RUN apk update -qq && apk add git
    RUN go get github.com/golang/protobuf/jsonpb
    RUN go get github.com/golang/protobuf/proto
    RUN go build .
    
    FROM alpine:3.7
    WORKDIR /usr/bin
    COPY --from=build /go/src/github.com/{$whoami}/testProject/testProject .
    EXPOSE 9888
    CMD ["./app"] --v
    

    this is a multistage dockerfile which you copy the project, fetch dependencies and build it, and then in second one, you just run it (by CMD ["./app"])

    if you want to do it in your way:

    FROM golang:1.10.2-alpine3.7
    RUN apk --no-cache add gcc g++ make ca-certificates
    WORKDIR /go/src/github.com/{$whoami}/testProject
    COPY . .
    RUN apk update -qq && apk add git
    RUN go get github.com/golang/protobuf/jsonpb
    RUN go get github.com/golang/protobuf/proto
    

    is the dockerfile you want (my suggestion is ofc first one cause it runs just by docker run command)

    PS: multistage dockerfile

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥50 STM32L431RCT6 定时器2中断发起ADC 采样问题
  • ¥15 如何通过交互分析得出某高危患者对放疗获益更多
  • ¥15 相关性分析中,p<0.05, r=0.29,怎么评价相关性呢
  • ¥15 docker部署Mongodb后输入命令报错?
  • ¥15 将下列流程图转变成python程序代码
  • ¥15 我需要全国每个城市的最新小区名字等数据。
  • ¥15 开发一个小区生态的小程序
  • ¥15 如何解决Excel中dependent dropdown list 的问题
  • ¥15 MddBootstrapInitialize2失败
  • ¥15 LCD Flicker