Home >Backend Development >Golang >Why Does My Go Web App in Docker Fail with 'standard_init_linux.go:190: exec user process caused 'no such file or directory''?
Docker Image Error: "standard_init_linux.go:190: exec user process caused "no such file or directory" when Running Go Web App
This error message indicates that the Docker image cannot find or execute the specified user process. The problem stems from missing dependencies or improper compilation parameters.
When building the Go web app, ensure that the webapp.go file imports the necessary packages, such as the net package. Additionally, the net import includes libc by default as a dynamically linked binary, which may be missing in the Docker image.
To resolve this issue, use the following compilation parameters:
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -a -tags netgo -ldflags '-w' -o mybin *.go
By specifying CGO_ENABLED=0, you disable CGO (Go's mechanism for calling C functions) and force pure Go compilation, eliminating the need for libc. GOOS=linux and GOARCH=amd64 indicate the target platform and architecture. -a builds a statically linked binary, and -ldflags '-w' strips unnecessary information from the binary.
After recompiling with these parameters, build the Docker image, and run it. The error should now be resolved, and the web app should function correctly within the container.
The above is the detailed content of Why Does My Go Web App in Docker Fail with 'standard_init_linux.go:190: exec user process caused 'no such file or directory''?. For more information, please follow other related articles on the PHP Chinese website!