在Alpine中找不到运行时/cgo [英] cannot find runtime/cgo in Alpine
问题描述
在我安装的 alpine:edge
容器中,通过
In an alpine:edge
container I installed go via
RUN apk add --no-cache musl-dev go
然后我尝试运行 go get github.com/golang/protobuf/protoc-gen-go
.
这将导致错误消息:
go: finding github.com/golang/protobuf/protoc-gen-go latest
go: finding github.com/golang/protobuf v1.3.1
go: downloading github.com/golang/protobuf v1.3.1
go: extracting github.com/golang/protobuf v1.3.1
# github.com/golang/protobuf/protoc-gen-go
loadinternal: cannot find runtime/cgo
protoc-gen-go: program not found or is not executable
现在查看代码,它在 ctxt.PackageFile [name]
上失败.
Now looking at the code, it fails on ctxt.PackageFile[name]
.
我仔细检查了/usr/lib/go/pkg/tool/linux_amd64/cgo
和/usr/lib/go/pkg/linux_amd64/runtime/cgo.一个
存在.
应按照 go env
的顺序排列:
GOARCH="amd64"
GOBIN=""
GOCACHE="/root/.cache/go-build"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/root/go"
GOPROXY=""
GORACE=""
GOROOT="/usr/lib/go"
GOTMPDIR=""
GOTOOLDIR="/usr/lib/go/pkg/tool/linux_amd64"
GCCGO="gccgo"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/dev/null"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build521273293=/tmp/go-build -gno-record-gcc-switches"
有人提示下一个地方在哪里或有什么问题吗?
Anyone any hints where to look next or what is wrong?
推荐答案
避免此问题的一种方法是强制静态构建禁用 cgo
.尝试使用以下命令构建二进制文件:
One way to avoid this issue is to force a static build disabling cgo
. Try building your binary with the following command:
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o yourBinaryName
如果您的应用程序中确实需要cgo,则可能需要安装gcc,musl-dev甚至是@abergmeier指出的build-base.您可以使用以下命令执行此操作:
If you actually need cgo in your app, you might want to install gcc, musl-dev and even build-base like @abergmeier pointed out. You can do this with this command:
RUN apk update && apk add --no-cache musl-dev gcc build-base
如果这些都不起作用,我会检查这个要点,声称它创建了一个能够编译原型的Dockerfile:基于Alpine(3.6)的Docker映像,带有支持Go的Protocol Buffers编译器"
If none of that works I would check out this gist claiming it creates a Dockerfile capable of compiling protobuffs: "Alpine (3.6) based docker image with Protocol Buffers compiler supporting Go"
这篇关于在Alpine中找不到运行时/cgo的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!