Golang app not compiling in docker

Hi all

Please see attached. if I compile my code directly on system, it works, when I compile/build into a docker images I get errors as per the attached.

Anyone seen this, I’m also attaching my docker file.

G

Dockerfile

FROM golang:alpine as build-env

RUN apk update && apk add bash ca-certificates git gcc g++ libc-dev

WORKDIR /scrubber

COPY . .

RUN go build -o scrubber .

CMD ./scrubber

Err.log → Output from above build.

Sending build context to Docker daemon 41.54MB

Step 1/6 : FROM golang:alpine as build-env

---> 14ee78639386

Step 2/6 : RUN apk update && apk add bash ca-certificates git gcc g++ libc-dev

---> Using cache

---> 159487736117

Step 3/6 : WORKDIR /scrubber

---> Using cache

---> 04f9d5590771

Step 4/6 : COPY . .

---> Using cache

---> 313c9ab381f8

Step 5/6 : RUN go build -o scrubber .

---> Running in 19c14cb0cbd2

e[91m# github.com/confluentinc/confluent-kafka-go/kafka

/usr/lib/gcc/x86_64-alpine-linux-musl/10.2.1/../../../../x86_64-alpine-linux-musl/bin/ld: vendor/github.com/confluentinc/confluent-kafka-go/kafka/librdkafka_vendor/librdkafka_glibc_linux.a(rdkafka_txnmgr.o): in function `rd_kafka_txn_set_fatal_error':

(.text+0x149): undefined reference to `__strdup'

/usr/lib/gcc/x86_64-alpine-linux-musl/10.2.1/../../../../x86_64-alpine-linux-musl/bin/ld: vendor/github.com/confluentinc/confluent-kafka-go/kafka/librdkafka_vendor/librdkafka_glibc_linux.a(rdkafka_txnmgr.o): in function `rd_kafka_txn_set_abortable_error':

(.text+0x683): undefined reference to `__strdup'

/usr/lib/gcc/x86_64-alpine-linux-musl/10.2.1/../../../../x86_64-alpine-linux-musl/bin/ld: vendor/github.com/confluentinc/confluent-kafka-go/kafka/librdkafka_vendor/librdkafka_glibc_linux.a(rdkafka_admin.o): in function `rd_kafka_NewTopic_new':

and this above message is repeated probably 50+ times

update,

I’ve added “librdkafka-dev pkgconf” to the docker file as modules to pull in, still getting same errors.

G

@georgelza maybe this GH issue has some clues to your compilation issue?

so being the noob at this. where do I add the “-tags dynamic” tags.

looking at some dogs it implies with the go build command, but with us doing a docker build, using a docker file, i never issue a go build command.

G

I think next I might try the golang docs, in particular the Docker information. Maybe start here?

https://hub.docker.com/_/golang

don’t think this is golang related, this is more docker and have feeling the combination of docker/golang and kafka.

surely someone else have deployed a go app accessing CP Kafka in K8s. be keen to see their docker file.

G

… let me add, my other client → receiving app is also golang and inside docker.
App 1, read text file, do some logic, drop onto Kafka topic.
App 2, consume topic (This app that I have problem with) more logic, and then send via gRPC to App 3, some more logic and then into a unstructured DB ( This app in docker works)
App 2, if just direct compiled/executed, it works, when attempting to build into docker image then have these problems.

G

checking, but looks like i got it build.

changed
RUN apk update && apk add bash ca-certificates git gcc g++ libc-dev
to
RUN apk update && apk add bash ca-certificates git gcc g++ libc-dev librdkafka-dev pkgconf

change
RUN go build -o scrubber .
to
RUN go build -tags musl -o scrubber .

G

1 Like