小编som*_*ude的帖子

如何以用户“nobody”的身份在暂存容器中运行我的 Go 应用程序?

我不想以 root 身份在 docker 容器中运行任何内容。我想要简约的图像。

我可以毫无问题地在暂存映像中运行我编译的 Go 应用程序。但是当我不希望它以 root 身份运行(我假设它以 root 身份运行)并在 dockerfile 中定义 USER nobody 时,我得到

014/10/25 06:07:10 Error response from daemon: Cannot start container 
4822f34e54e20bb580f8cd1d38d7be3c828f28595c2bebad6d827a17b4c2fe21: 
finalize namespace setup user get supplementary groups Unable to find user nobody
Run Code Online (Sandbox Code Playgroud)

这是我的 dockerfile

FROM scratch
ADD lichtpunkt_go_linux_amd64 /lichtpunkt_go_linux_amd64
ADD web /web
USER nobody
CMD ["./lichtpunkt_go_linux_amd64"]
EXPOSE 3001
Run Code Online (Sandbox Code Playgroud)

编辑 - - - - - -

事实证明,划痕是空的,非常空。

RUN useradd 会执行 /bin/sh -c useradd 但没有 /bin/sh 。RUN ["useradd"] 将直接执行。但没有 useradd。id 必须添加 rootfs.tar 并从零开始构建内容。

我将使用 debian,因为我不会在容器中以 …

go docker linux-containers

9
推荐指数
3
解决办法
7418
查看次数

如何实现GetStringValueByField(n interface {},field_name string)字符串

我试图实现一个方法来从任意struct-field获取一个值作为struct给出的字符串和fieldname作为字符串.

反映它始终是惊慌失措.

恐慌:反映:在接口上调用reflect.Value.FieldByName值goroutine 16 [运行]

// attempt to implement GetStringValueByFieldName()
package main

import "fmt"

import "reflect"
import "strconv"

func main() {

    a:=Order{A:"asdf", B:123}
    fmt.Println(a)
    fmt.Println(Test1(a, "A"))
    fmt.Println(Test1(a, "B"))
}

type Order struct {
    A  string
    B  int64
}
func Test1 (n interface{}, field_name string) string {
    var x string
    s := reflect.ValueOf(&n).Elem()
    x, ok := s.FieldByName(field_name).Interface().(string)
    if ok {
        fmt.Println(ok)
    }
    return x
}

func GetStringValueByFieldName(n interface{}, field_name string) string {
    ps := reflect.ValueOf(&n)
    // struct
    s := ps.Elem()
    if …
Run Code Online (Sandbox Code Playgroud)

reflection go

1
推荐指数
1
解决办法
649
查看次数

标签 统计

go ×2

docker ×1

linux-containers ×1

reflection ×1