Golang docker multi-stage build failing to run: exec: "go": executable file not found in $PATH

Ewan :

When deploying a simple API with a Docker multi-stage build the following error is being thrown:

$ docker build -t api:latest .
[...]
$ docker run -p 4880:4880 --rm --name=api api:latest
2019/01/29 23:02:15 exec: "go": executable file not found in $PATH

As my application is not calling go from anywhere (or any exec.Command) I ran a go mod vendor so I could check the dependency source code and found the following:

vendor/github.com/lib/pq/oid/gen.go
12:     "os/exec"
64:     cmd := exec.Command("gofmt")

Could this be the issue and if so how can I fix it? I am sure I have managed to deploy github.com/lib/pq in a multi-stage build before but I am currently stuck.

Many thanks and Happy Hacking.

Dockerfile

FROM golang:1-alpine AS builder
ENV GO111MODULE=on
RUN apk --no-cache add ca-certificates git
WORKDIR /app
# Copy go module info first...
COPY go.mod .
COPY go.sum .
# ...then download to cache dependencies between builds
RUN go mod download
COPY . .
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -installsuffix cgo -ldflags '-extldflags "-static"' -o api cmd/api/

FROM scratch
WORKDIR /app
COPY --from=builder /app/api /app/
COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/
EXPOSE 8080
ENTRYPOINT ["./api"]
Jorden :

Your actual build line:

RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -installsuffix cgo -ldflags '-extldflags "-static"' -o api cmd/api/

is missing a relative path in front of cmd, making it instead be ./cmd/api will result in a successful build/run. cmd/api is a real thing apparently, https://golang.org/cmd/api/, so it's not erring out, but also not doing what you are expecting it to do. If you type go run cmd/api in your terminal you should see a ton of output unrelated to your application.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

exec: "gcc": executable file not found in %PATH% when trying go build

"exec: \"go\": executable file not found in $PATH"

godep: exec: "go": executable file not found in $PATH

Getting error executable file not found in $PATH when trying verbose run docker container or when docker exec

Docker Go image: starting container process caused: exec: "app": executable file not found in $PATH: unknown

Docker container build faild: "exec: \"flask\": executable file not found in $PATH": unknown

Go moq : running "moq": exec: "moq": executable file not found in $PATH

exec: executable file not found in $PATH

"sqlplus": executable file not found in $PATH" when running a command with docker exec

docker-exec failed: "cd": executable file not found in $PATH

docker local registry "exec: \"htpasswd\": executable file not found in $PATH"

exec: "com.docker.cli": executable file not found in $PATH

exec: "docker-runc": executable file not found in $PATH: unknown

Docker's "executable file not found in $PATH: unknown" trying to run "cd"

docker: executable file not found in $PATH

exec: "sqlboiler": executable file not found in $PATH

"exec: "python": executable file not found in $PATH

package code.google.com/p/go.example/hello: exec: "hg": executable file not found in %PATH%. How to get remote golang packages?

hyperledger fabric - "go": executable file not found in $PATH

Docker Base Simple image : Cannot start container XXX: exec: "cat": executable file not found in $PATH

Error running docker container: starting container process caused "exec: \"python\": executable file not found in $PATH": unknown

Docker --mount throws: executable file not found in $PATH"

Docker, \"ping\": executable file not found in $PATH": unknown

Docker elasticsearch 1.7 executable file not found in $PATH"

Docker compose executable file not found in $PATH": unknown

Docker Nodejs Multi Stage build Error. Dist not found

How to add local dependencies in Go Docker multi-stage build?

gcloud app deploy says: exec: "git": executable file not found in $PATH

System error: exec: "deployment": executable file not found in $PATH