![](/img/trans.png)
[英]Docker Go image: starting container process caused: exec: "app": executable file not found in $PATH: unknown
[英]starting container process caused "exec: \"go\": executable file not found in $PATH": unknown
我正在尝试容器化并使用 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\\": executable file not found in $PATH
匹配的 Dockerfile 将具有CMD ["go", "./main"]
而不是CMD ["./main"]
。
因此,要么您意外地构建了不同的 Dockerfile,要么在使用该映像运行容器时更改了命令。 特别是,如果您正在使用docker-compose
,请确保您没有设置command: go ./main
或entrypoint: go
,这两者都可能导致此行为。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.