执行用户进程导致

执行用户进程导致

本文介绍了standard_init_linux.go:190:执行用户进程导致“没有这样的文件或目录”。带有Go Basic Web App的Docker的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

非常简单的网络应用是在Go中创建的

The very basic web app is created in Go

package main

import(
   "fmt"
   "net/http"
   "os"
)

func hostHandler(w http.ResponseWriter, r *http.Request){
    name, err :=os.Hostname()

    if err != nil {
           panic(err)
        }

        fmt.Fprintf(w, "<h1>HOSTNAME: %s</h1><br>",name)
        fmt.Fprintf(w, "<h1>ENVIRONMENT VARS: </h1><br>")
        fmt.Fprintf(w, "<ul>")

        for _, evar := range os.Environ(){
            fmt.Fprintf(w, "<li>%s</li>",evar)
        }
        fmt.Fprintf(w, "</ul>")

}

func rootHandler(w http.ResponseWriter, r *http.Request){

    fmt.Fprintf(w, "<h1>Awesome site in Go!</h1><br>")
    fmt.Fprintf(w, "<a href='/host/'>Host info</a><br>")

}

func main() {

        http.HandleFunc("/", rootHandler)
        http.HandleFunc("/host/", hostHandler)
        http.ListenAndServe(":8080", nil)


}

Docker File

Docker File for it

FROM scratch
WORKDIR /home/ubuntu/go
COPY webapp /
EXPOSE 8080
CMD ["/webapp"]

图像已成功构建

ubuntu@ip-172-31-32-125:~/go/src/hello$ docker build -t "webapp" .
Sending build context to Docker daemon  6.152MB
Step 1/5 : FROM scratch
 --->
Step 2/5 : WORKDIR /home/ubuntu/go
 ---> Using cache
 ---> 8810a06c58c7
Step 3/5 : COPY webapp /
 ---> Using cache
 ---> d75222363d3a
Step 4/5 : EXPOSE 8080
 ---> Using cache
 ---> 45de0853de8e
Step 5/5 : CMD ["/webapp"]
 ---> Using cache
 ---> e9f9031f3632
Successfully built e9f9031f3632
Successfully tagged webapp:latest

但是当我运行docker时,它的节目错误。

But when i run the docker its show error.

ubuntu@ip:~/go/src/hello$ docker run webapp
standard_init_linux.go:190: exec user process caused "no such file or directory"

请指导问题所在,我是docker的新手,然后就去了。

Please guide what is the issue, I am new to docker and go.

与环境相关的信息

ubuntu@ip:~/go/src/hello$ ls
Dockerfile  webapp
ubuntu@ip:~/go/src/hello$ echo $GOPATH
/home/ubuntu/go

代码原为使用 go build webapp.go 命令

推荐答案

未编译的文件可能意味着文件丢失,缺少解释程序的脚本,或缺少库的可执行文件。在这种情况下,默认情况下,net import引入libc作为动态链接二进制文件。您应该能够在二进制文件上使用 ldd 看到它。

File not found can mean the file is missing, a script missing the interpreter, or an executable missing a library. In this case, the net import brings in libc by default, as a dynamic linked binary. You should be able to see that with ldd on your binary.

要修复此问题,您需要传递一些额外的标志:

To fix it, you'll need to pass some extra flags:

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

以上内容来自:

这篇关于standard_init_linux.go:190:执行用户进程导致“没有这样的文件或目录”。带有Go Basic Web App的Docker的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-24 22:15