一、异常
go build 时出现 undefined: kafka.Message
二、解决方法
1、打开动态编译
ENV CGO_ENABLED=1
2、若是跨平台编译,目标平台是linux
需要添加:-tags musl
3、实例
FROM golang:1.13-alpine AS builder
ENV GOOS linux
ENV GOARCH amd64
# missed this very obvious change
ENV CGO_ENABLED 1
RUN apk update && apk upgrade && \
apk add --no-cache git
# needed for gcc
RUN apk add --no-cache git build-base
WORKDIR /build
COPY . ./
# confluent-kafka-go recommends musl tags for alpine linux builds
RUN go build -tags musl
三、参考
1、 https://github.com/confluentinc/confluent-kafka-go/issues/479
2、https://github.com/confluentinc/confluent-kafka-go