Reputation: 121
I have gcc on windows.
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.
My docker file:
FROM golang:alpine
RUN mkdir /app
WORKDIR /app
ADD . /app
RUN go build -o main .
EXPOSE 8080
CMD [ "app/main" ]
When I try to build image I get error:
exec: "gcc": executable file not found in $PATH
Upvotes: 12
Views: 13469
Reputation: 1
It worked for me:
add
CGO_ENABLED=0 GOOS=linux GOARCH=amd64
RUN
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o main ./
Upvotes: 0
Reputation: 397
Add the gcc tools fixed the problem.
RUN apk add build-base
Also you can the this:
RUN apk --no-cache add make git gcc libtool musl-dev ca-certificates dumb-init
Upvotes: 11
Reputation: 1752
I encountered the same problem when building a go app using an alpine image. Installing gcc fixed the problem. Here is how your Dockerfile should look like:
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" ]
Upvotes: 29