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

时间:2018-11-03 07:01:32

标签: docker go

我已经创建了dockerfile,成功构建了它,但是当我运行它

  

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

返回错误

  

docker:来自守护程序的错误响应:OCI运行时创建失败:container_linux.go:348:启动容器进程导致“ exec:\” go \”:在$ PATH中找不到可执行文件”:未知。

这是我的Docker文件

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 个答案:

答案 0 :(得分:1)

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

这是一个多阶段的dockerfile,您可以复制项目,获取依赖项并进行构建,然后在第二个文件中,只需运行它(通过CMD ["./app"]

如果您想以自己的方式这样做:

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

是您想要的dockerfile(我的建议是第一个,因为它仅通过docker run命令运行)

PS:multistage dockerfile