gpt4 book ai didi

docker - "exec:\"去\": executable file not found in $PATH"

转载 作者:IT王子 更新时间:2023-10-29 01:08:19 27 4
gpt4 key购买 nike

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

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

返回错误

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.

这是我的 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

最佳答案

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(我的建议是ofc第一个因为它只通过docker run命令运行)

附言:multistage dockerfile

关于docker - "exec:\"去\": executable file not found in $PATH",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53129178/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com