Reputation: 7591
I'm getting executable file not found in $PATH: unknown error while trying to run docker image of golang project. Following is my docker file.
FROM golang:latest
LABEL maintainer = "Nisal Perera <[email protected]>"
RUN mkdir -p /go/src/github.com/user/app/
COPY . /go/src/github.com/user/app/
WORKDIR /go/src/github.com/user/app/
RUN go get -u github.com/golang/dep/cmd/dep
#RUN dep init
RUN dep ensure
RUN go build
CMD ["go run main.go"]
The error I'm getting is the following
docker: Error response from daemon: OCI runtime create failed: container_linux.go:370: starting container process caused: exec: "go run main.go": executable file not found in $PATH: un
known.
Please help me with this. thanks
Upvotes: 1
Views: 5873
Reputation: 44360
You dont need to use go run ...
since you previously run go build
, built file will be named after directory and looks like its app
, try CMD ["./app"]
BTW the right usage of CMD
in your case would be CMD ["go", "run", "main.go"]
, the error you have is related to CMD
command its assume go run main.go
is one file but it's not.
Upvotes: 9
Reputation: 2115
You're trying to use the CMD
clause in its exec form so you have to split the command and its arguments. The accepted format is
CMD ["executable","param1","param2"]
So yours would be
CMD ["go", "run", "main.go"]
Upvotes: 4
Reputation: 65
You are getting this error as the file "main.go" is not available at the working directory where it is executing the "go run main.go" command.
Please check the main.go file is available or not if yes then please define the complete path for the main.go file and try.
Upvotes: 1