docker - 在 Linux 上使用 confluent-kafka-go 构建 Go 应用程序

标签 docker go apache-kafka

我正在尝试使用我的 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: #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"]

关于docker - 在 Linux 上使用 confluent-kafka-go 构建 Go 应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54202373/

相关文章:

python - pycharm_helpers 的拉取访问被拒绝,存储库不存在或可能需要 'docker login'

bash - 读取stdout时如何保留shell脚本行距?

java - 时间窗口聚合中的 Kafka 流问题

docker - Kubectl 随机返回 "TLS handshake timeout"(在 localhost K8s 上运行)

docker - 连接到 dockerized Rethinkdb

docker - 创建InfluxDB Docker容器时,如何设置保留策略以将数据存储30天并以1天的碎片数存储

go - 一例 `all goroutines are asleep - deadlock!`我不知道为什么

go - 如何修复这个简单程序中的 'declared but not used' 编译器错误?

apache-kafka - Kafka Consumer poll() 方法被阻塞

java - 为什么 Kafka KTable 缺少条目?