英文:
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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论