douer9399
2018-11-03 07:01
浏览 656

“ 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

    点赞 评论