我正在尝试使用我的go应用程序创建一个docker镜像。该应用程序(是在MacOS上开发的)取决于confluent-kafka-go
,而后者又取决于我安装在Docker镜像中的librdkafka-dev
,如下所示:
FROM golang:1.1
RUN apt-get update
RUN apt-get -y install librdkafka-dev
VOLUME /workspace
WORKDIR /workspace/src/my/app/folder
ENTRYPOINT ["/bin/sh", "-c"]
我收到以下错误:
我/app/folder/vendor/github.com/confluentinc/confluent-kafka-go/kafka
../folder/vendor/github.com/confluentinc/confluent-kafka-go/kafka/00version.go:44:2:错误:#error“confluent-kafka-go需要librdkafka v0.11.5或更高版本。请安装最新的来自Confluent储存库的librdkafka版本,请参见http://docs.confluent.io/current/installation.html“
据我了解,最新版本已安装。
我该如何解决?
最佳答案
几周前我也遇到过类似的问题。 IIRC confluent-kafka-go
需要librdkafka-dev
的最新版本,而该版本尚未发布给alpine或其他人。
虽然我能够为ubuntu找到它,所以我的解决方案(比我期望的要复杂得多,但它确实有效)是从干净的ubuntu开始,安装librdkafka-dev
,安装我想要的Go版本并在docker内编译。
外观如下:
FROM ubuntu
# Install the C lib for kafka
RUN apt-get update
RUN apt-get install -y --no-install-recommends apt-utils wget gnupg software-properties-common
RUN apt-get install -y apt-transport-https ca-certificates
RUN wget -qO - https://packages.confluent.io/deb/5.1/archive.key | apt-key add -
RUN add-apt-repository "deb [arch=amd64] https://packages.confluent.io/deb/5.1 stable main"
RUN apt-get update
RUN apt-get install -y librdkafka-dev
# Install Go
RUN add-apt-repository ppa:longsleep/golang-backports
RUN apt-get update
RUN apt-get install -y golang-1.11-go
# build the library
WORKDIR /go/src/gitlab.appsflyer.com/rantav/kafka-mirror-tester
COPY *.go ./
COPY // the rest of your go files. You may copy recursive if you want
COPY vendor vendor
RUN GOPATH=/go GOOS=linux /usr/lib/go-1.11/bin/go build -a -o main .
EXPOSE 8000
ENTRYPOINT ["./main"]