登录
首页 >  Golang >  Go问答

容器进程启动时:“exec:\”go \“:在$ PATH中找不到可执行文件”的错误解决办法

来源:stackoverflow

时间:2024-03-01 10:39:27 351浏览 收藏

本篇文章主要是结合我之前面试的各种经历和实战开发中遇到的问题解决经验整理的,希望这篇《容器进程启动时:“exec:\”go \“:在$ PATH中找不到可执行文件”的错误解决办法》对你有很大帮助!欢迎收藏,分享给更多的需要的朋友学习~

问题内容

我正在尝试使用 docker-compose 容器化并启动我的 go lang 应用程序, 根据日志,图像已成功构建,但我的容器不适用于 docker-compose up,并且它会向我的控制台抛出以下错误。

无法启动服务应用程序:oci 运行时创建失败:container_linux.go:346: 启动容器进程导致“exec: \”go\”:在 $path 中找不到可执行文件”:未知

这是我的 docker 文件的样子。

ARG GO_VERSION=1.13

FROM golang:${GO_VERSION}-alpine AS builder

# We create an /app directory within our
# image that will hold our application source
# files
RUN mkdir /raedar

# Create the user and group files that will be used in the running container to
# run the process as an unprivileged user.
RUN mkdir /user && \
    echo 'nobody:x:65534:65534:nobody:/:' > /user/passwd && \
    echo 'nobody:x:65534:' > /user/group

# Install git.
# Git is required for fetching the dependencies.
# Allow Go to retrieve the dependencies for the buld
RUN apk update && apk add --no-cache ca-certificates git

RUN apk add --no-cache libc6-compat

# Force the go compiler to use modules 
ENV GO111MODULE=on

ADD . /raedar/


WORKDIR /raedar/

RUN go get -d -v golang.org/x/net/html

COPY go.mod go.sum ./

COPY . .

# Compile the binary, we don't want to run the cgo
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o bin/main cmd/app/main.go


# Final stage: the running container.
FROM scratch AS final

WORKDIR /root/

# Import the user and group files from the first stage.
COPY --from=builder /user/group /user/passwd /etc/

# Import the Certificate-Authority certificates for enabling HTTPS.
COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/

# Import the compiled executable from the first stage.
COPY --from=builder /raedar/bin/main .

EXPOSE 8080
# Perform any further action as an unprivileged user.
USER nobody:nobody

# Run the compiled binary.
CMD ["./main"]

解决方案


该错误表明您正在尝试运行 go,而不是 。/main

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

匹配的 Dockerfile 将包含 CMD ["go", "./main"] 行,而不是 CMD ["./main"]

因此,要么您意外地构建了不同的 Dockerfile,要么在使用该映像运行容器时更改了命令。特别是,如果您使用 docker-compose,请确保您没有设置 command: go ./mainentrypoint: go,其中任何一个都可能导致此行为。

好了,本文到此结束,带大家了解了《容器进程启动时:“exec:\”go \“:在$ PATH中找不到可执行文件”的错误解决办法》,希望本文对你有所帮助!关注golang学习网公众号,给大家分享更多Golang知识!

声明:本文转载于:stackoverflow 如有侵犯,请联系study_golang@163.com删除
相关阅读
更多>
最新阅读
更多>
课程推荐
更多>