linux 一些可执行文件显示“没有这样的文件或目录”后,在Docker中运行,而有些不是

92dk7w1h  于 2023-02-15  发布在  Linux
关注(0)|答案(1)|浏览(126)

这是我的Dockerfile:

FROM gcr.io/distroless/static:nonroot
WORKDIR /
COPY ls .
COPY tail .
COPY test .
COPY manager .
ENTRYPOINT ["/manager"]

[root@master go-docker-test]# docker build -t strangething:v1.13 .
[root@master go-docker-test]# docker run -d strangething:v1.13
[root@master go-docker-test]# docker logs b2

它显示:

exec /manager: no such file or directory

我很确定它就在那里。我用潜水来看它:

[Layers]───────────────────────────────────────────────────────────────────── [● Current Layer Contents]──────────────────────────────────────────────────
Cmp Image ID                     Size  Command                                Permission    UID:GID       Size  Filetree
    sha256:cb60fb9b862c6a89f9  2.3 MB  FROM sha256:cb60fb9b862c6a89f9         drwxr-xr-x        0:0     2.3 MB  ├── .
    sha256:3e884d7c2d4ba9bac6  118 kB  COPY ls . # buildkit                   drwxr-xr-x        0:0        0 B  │   ├── bin
    sha256:e75e9da8f1605f7944   67 kB  COPY tail . # buildkit                 drwxr-xr-x        0:0        0 B  │   ├── boot
    sha256:7a0f1970f36a364672  1.8 MB  COPY test . # buildkit                 drwxr-xr-x        0:0        0 B  │   ├── dev
    sha256:c9ab59cb1ce11477ca   47 MB  COPY manager . # buildkit              drwxr-xr-x        0:0     220 kB  │   ├─⊕ etc
                                                                              drwxr-xr-x 65532:65532        0 B  │   ├─⊕ home
[Layer Details]────────────────────────────────────────────────────────────── drwxr-xr-x        0:0        0 B  │   ├── lib
                                                                              drwxr-xr-x        0:0        0 B  │   ├── proc
Digest: sha256:c9ab59cb1ce11477cac4d634bb81cf7316c344b50f01a62a8e5ddcf355d5fe drwx------        0:0        0 B  │   ├── root
cf                                                                            drwxr-xr-x        0:0        0 B  │   ├── run
Tar ID: 998c57d00785ccffaf3b308a529c7f816633897097d1ef6519269a8e3c5af59b      drwxr-xr-x        0:0        0 B  │   ├── sbin
Command:                                                                      drwxr-xr-x        0:0        0 B  │   ├── sys
COPY manager . # buildkit                                                     drwxrwxrwx        0:0        0 B  │   ├── tmp
                                                                              drwxr-xr-x        0:0     2.1 MB  │   ├─⊕ usr
[Image Details]────────────────────────────────────────────────────────────── drwxr-xr-x        0:0     1.8 kB  │   └─⊕ var
                                                                              -rwxr-xr-x        0:0     118 kB  ├── ls
Total Image size: 51 MB                                                       -rwxr-xr-x        0:0      47 MB  ├── manager
Potential wasted space: 0 B                                                   -rwxr-xr-x        0:0      67 kB  ├── tail
Image efficiency score: 100 %                                                 -rwxr-xr-x        0:0     1.8 MB  └── test

Count   Total Space  Path

这个文件树或多或少让我感到困惑。
不管怎样,奇怪的是,ls tail manager不能执行,但test可以执行。
在我将ENTRYPOINT ["/manager"]更改为ENTRYPOINT ["/test"]之后:

[root@master go-docker-test]# docker logs c11
empty

test是由test.go编写的程序,我自己写的:

package main

import (
        "fmt"
)
type Per struct {
        Name string
        Age int
}
type Person struct {
        Name string
        Age int
        Lov Per
}

func main() {
        var one Person
        one.Name="abc"
        one.Age=11
        var two Per
        one.Lov=two
        if one.Lov != (Per{}){
                fmt.Println("not empty!")
        }else {
                fmt.Println("empty")
        }
}
vwkv1x7d

vwkv1x7d1#

在阅读silh的回答并再次阅读了kubebuilder Dockerfile之后,我通过在go build中添加CGO_ENABLED=0来解决这个问题,它将动态链接器更改为静态链接器。

CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -a -o manager main.go

至少no such file or directory已经走了。

相关问题