Home > Blockchain >  docker run command gives error no such file or directory
docker run command gives error no such file or directory

Time:02-02

So I am a novice to Docker and Golang. I created a REST API in go-gin framework and a docker image and when I am running the image it gives me following error:

docker: Error response from daemon: failed to create shim task: OCI runtime create failed: runc create failed: unable to start container process: exec: "/app/main": stat /app/main: no such file or directory: unknown.

My command for running the image is: docker run -d -p 3000:3000 json-crud "json-crud" is the name of the image.

Following is my Dockerfile content:

FROM golang:latest
RUN mkdir /app
ADD . /app
WORKDIR /app
RUN go get ./...
RUN go mod tidy
RUN go mod download
RUN go build /app
CMD ["/app/main"]

My local files directory is as follow:

enter image description here

This is my go.mod file:

module nishanktiwari/json-crud

go 1.19

require github.com/gin-gonic/gin v1.8.2

require (
    github.com/gin-contrib/sse v0.1.0 // indirect
    github.com/go-playground/locales v0.14.0 // indirect
    github.com/go-playground/universal-translator v0.18.0 // indirect
    github.com/go-playground/validator/v10 v10.11.1 // indirect
    github.com/goccy/go-json v0.9.11 // indirect
    github.com/json-iterator/go v1.1.12 // indirect
    github.com/leodido/go-urn v1.2.1 // indirect
    github.com/mattn/go-isatty v0.0.16 // indirect
    github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421 // indirect
    github.com/modern-go/reflect2 v1.0.2 // indirect
    github.com/pelletier/go-toml/v2 v2.0.6 // indirect
    github.com/ugorji/go/codec v1.2.7 // indirect
    golang.org/x/crypto v0.0.0-20211215153901-e495a2d5b3d3 // indirect
    golang.org/x/net v0.4.0 // indirect
    golang.org/x/sys v0.3.0 // indirect
    golang.org/x/text v0.5.0 // indirect
    google.golang.org/protobuf v1.28.1 // indirect
    gopkg.in/yaml.v2 v2.4.0 // indirect
)

CodePudding user response:

After go build /app try to add an ls /app to see if the main binary got generated correctly. You will need to figure out why the compilation failed and then fix it to get everything to work correctly.

Hope this helps.

CodePudding user response:

You haven't shown your go.mod file so I'm guessing here. But this could be explained if your module is named something other than:

module main

Note that the go build /app command during your Docker build does not specify an output binary. If not specified, it defaults to the module name. Try changing the command to go build -o main /app and try again.

  • Related