当前在Linux/amd64上使用Golang和Docker Scratch尚未实现。

huangapple go评论76阅读模式
英文:

user: Current not implemented on linux/amd64 with golang using docker scratch

问题

我已经使用这个教程来编译我的Go应用程序,以在基于scratch的容器中运行。

我的Go代码使用了os/user中的user.Current()函数。当我使用博客文章中的技术运行容器时,会出现以下错误:

user: Current not implemented on linux/amd64

更详细地说明一下:

这是用于编译的命令:

CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -o main .

这是用于创建镜像的Dockerfile(基于scratch):

FROM scratch
ADD ca-certificates.crt /etc/ssl/certs/
ADD main /
ENTRYPOINT ["/main"]

这是用于运行容器的命令:

sudo docker run -it -v /var/run/docker.sock:/var/run/docker.sock --rm 813

有人遇到过这个问题吗?有解决方案吗?

英文:

I have used this tutorial to compile my go app to run on container derived from scratch.

My go code uses user.Current() from os/user. When I use the technique from the blog post I get the following error when running the container:

user: Current not implemented on linux/amd64

To elaborate more:

This is the command used to compile:

CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -o main .

This is the Dockerfile used to create the image (scratch based):

FROM scratch
ADD ca-certificates.crt /etc/ssl/certs/
ADD main /
ENTRYPOINT ["/main"]

This is the command used to run the container:

sudo docker run -it -v /var/run/docker.sock:/var/run/docker.sock --rm 813

Did anyone encounter this? Any solution?

答案1

得分: 4

os/user包在Linux上使用getpwuid_r系统调用来实现用户信息的查找,因此在使用CGO_ENABLED=0编译时将无法工作。

虽然在Go中实现一个/etc/passwd解析器听起来很简单,但getpwuid函数可能会从不同的来源检索用户信息。例如,在某些系统上,它可能使用LDAP目录。因此,实现相同功能的唯一方法是委托给C库。

英文:

The os/user package's user info lookup on Linux is implemented using the getpwuid_r system call, so will not work when compiled with CGO_ENABLED=0.

While implementing a /etc/passwd parser in Go sounds simple, the getpwuid function may retrieve the user information from a different source. For instance, on some systems it might use an LDAP directory. So the only way to get parity is to delegate to the C library.

huangapple
  • 本文由 发表于 2015年4月27日 22:31:49
  • 转载请务必保留本文链接:https://go.coder-hub.com/29898620.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定