Home > Backend Development > Golang > How to Fix Docker's 'standard_init_linux.go:190: exec user process caused \'no such file or directory\'' Error in a Go Web App?

How to Fix Docker's 'standard_init_linux.go:190: exec user process caused \'no such file or directory\'' Error in a Go Web App?

Susan Sarandon
Release: 2024-12-18 16:54:14
Original
163 people have browsed it

How to Fix Docker's

Resolving Docker Error: "standard_init_linux.go:190: exec user process caused "no such file or directory"" with a Go Web App

When running a basic Go web application in Docker, you may encounter an error stating: "standard_init_linux.go:190: exec user process caused "no such file or directory"." This issue arises due to a missing file, script interpreter, or executable library.

In this case, the net import involves libc as a dynamic linked binary. To resolve the issue, you need to specify additional flags during compilation:

CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -a -tags netgo -ldflags '-w' -o mybin *.go
Copy after login

Explanation of the Flags:

  • CGO_ENABLED=0: Disables Cgo, which is used for interfacing with C code.
  • GOOS=linux: Specifies the target operating system as Linux.
  • GOARCH=amd64: Specifies the target architecture as amd64 (64-bit).
  • -a: Rebuilds all Go files.
  • -tags netgo: Tags the program to use the Go standard library's net package.
  • -ldflags '-w': Creates a statically linked executable (removes dependencies on shared libraries).
  • -o mybin: Specifies the output binary name as "mybin".

By using these flags, you are creating a statically linked executable that does not depend on external libraries. This should resolve the "no such file or directory" error when running the application in Docker.

The above is the detailed content of How to Fix Docker's 'standard_init_linux.go:190: exec user process caused \'no such file or directory\'' Error in a Go Web App?. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template