Go语言 当尝试构建docker镜像时,我得到““gcc”:在$PATH中找不到可执行文件”

nlejzf6q  于 2023-04-18  发布在  Go
关注(0)|答案(3)|浏览(212)

我在Windows上有GCC。

C:\Users\jkrov>gcc --version
gcc (MinGW.org GCC-8.2.0-5) 8.2.0
Copyright (C) 2018 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

我的docker文件:

FROM golang:alpine
RUN mkdir /app
WORKDIR /app
ADD . /app
RUN go build -o main .
EXPOSE 8080
CMD [ "app/main" ]

当我尝试构建图像时,我得到错误:

exec: "gcc": executable file not found in $PATH
nfg76nw0

nfg76nw01#

我在使用alpine镜像构建go应用时遇到了同样的问题。安装gcc解决了这个问题。下面是你的Dockerfile应该是这样的:

FROM golang:alpine
RUN apk add build-base
RUN mkdir /app
WORKDIR /app
ADD . /app
RUN go build -o main .
EXPOSE 8080
CMD [ "app/main" ]
a1o7rhls

a1o7rhls2#

添加gcc工具修复了问题。

RUN apk add build-base

你也可以这样:

RUN apk --no-cache add make git gcc libtool musl-dev ca-certificates dumb-init
sq1bmfud

sq1bmfud3#

它为我工作:addCGO_ENABLED=0 GOOS=linux GOARCH=amd64RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o main ./

相关问题