阿尔派(Alpine)Docker镜像__isnan:找不到符号

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

Alpine docker image __isnan: symbol not found

问题

这是我用来构建Golang应用程序和worker的Dockerfile:

FROM golang:1.15 AS build

RUN mkdir -p /go/api/proj

WORKDIR /go/api/proj

COPY go.* ./

RUN go mod download

COPY . .

RUN go mod tidy

RUN go build -o proj ./api/

RUN go build -o worker ./worker/

FROM alpine:3.14

WORKDIR /

RUN apk add libc6-compat cmake

RUN ln -s /lib/libc.musl-x86_64.so.1 /lib/ld-linux-x86-64.so.2

COPY . .

COPY --from=build /go/api/proj/proj .

COPY --from=build /go/api/proj/worker .

EXPOSE 80

CMD ["./worker"]

我不得不添加libc6-compat,因为worker中的kafka设置与alpine的musl库不兼容。

当我尝试在Docker容器中运行worker时,我收到了以下错误:

Error relocating ./worker: __strdup: symbol not found
Error relocating ./worker: __isnan: symbol not found
Error relocating ./worker: __strndup: symbol not found

有人能够提供出现问题的原因和解决方法吗?

我在worker中使用的是confluent kafka,这可能是出现此错误的原因。

英文:

Here's the Dockerfile I am using to build a Golang application and a worker

FROM golang:1.15 AS build

RUN mkdir -p /go/api/proj

WORKDIR /go/api/proj

COPY go.* ./

RUN go mod download

COPY . .

RUN go mod tidy

RUN go build -o proj ./api/

RUN go build -o worker ./worker/

FROM alpine:3.14

WORKDIR /

RUN apk add libc6-compat cmake

RUN ln -s /lib/libc.musl-x86_64.so.1 /lib/ld-linux-x86-64.so.2

COPY . .

COPY --from=build /go/api/proj/proj .

COPY --from=build /go/api/proj/worker .

EXPOSE 80

CMD ["./worker"]

I had to add libc6-compat because kafka setup in worker wasn't compatible with musl library of alpine

Here's the error I received when trying to run worker in docker container

Error relocating ./worker: __strdup: symbol not found
Error relocating ./worker: __isnan: symbol not found
Error relocating ./worker: __strndup: symbol not found

Can someone suggest what's going wrong here and solution for it?

I am using confluent kafka in worker which may be the reason for this error.

答案1

得分: 1

有人能建议一下这里出了什么问题,并提供解决方案吗?

你在这里做的是:

RUN ln -s /lib/libc.musl-x86_64.so.1 /lib/ld-linux-x86-64.so.2

这是在假装Musl是GLIBC。但实际上它们是不同的,所以这样是行不通的。

根据Musl FAQ

二进制兼容性非常有限,但随着新版本的Musl,它将逐渐增加。目前,一些链接了GLIBC的共享库可以在Musl上加载,但是如果将Musl替换为/lib/ld-linux.so.2,除了最简单的链接了GLIBC的应用程序外,其他大部分应用程序都会失败。

所以,你应该将worker二进制文件构建为使用Musl,而不是先使用GLIBC构建,然后尝试在Musl上运行它。

英文:

> Can someone suggest what's going wrong here and solution for it?

What you are doing here:

> RUN ln -s /lib/libc.musl-x86_64.so.1 /lib/ld-linux-x86-64.so.2

is pretending that Musl is GLIBC. It isn't, and that doesn't work.

From Musl FAQ:

> Binary compatibility is much more limited, but it will steadily increase with new versions of musl. At present, some glibc-linked shared libraries can be loaded with musl, but all but the simplest glibc-linked applications will fail if musl is dropped-in in place of /lib/ld-linux.so.2.

Instead of building the worker binary against GLIBC and then trying to run it with Musl, you should build it against Musl.

huangapple
  • 本文由 发表于 2022年10月8日 02:27:44
  • 转载请务必保留本文链接:https://go.coder-hub.com/73991313.html
匿名

发表评论

匿名网友

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

确定