confluentinc/confluent-kafka-go

Scratch base image in Dockerfile doesn't work after 1.5.2

emretanriverdi opened this issue · 3 comments

Description

Hi,

Dockerfile with Scratch base image works up until v1.4.2.
Doesn't work starting from versions 1.5.2 and above and writes this error:

Failed to resolve 'kafka-cluster.local:9092': Bad address (after 0ms in state CONNECT, 4 identical error(s) suppressed)

This error is not seen in debian:stretch-slim

How to reproduce

Just use this Dockerfile:

FROM golang:1.15 as prod-build

WORKDIR /app
COPY . .

RUN go mod download
RUN go build -ldflags="-w -s -extldflags -static" -o /app/my-app

# runtime container setup
FROM scratch

WORKDIR /app
COPY --from=prod-build /app/my-app /app/my-app
COPY --from=prod-build /app/resources/ /app/resources

EXPOSE 7575
ENTRYPOINT ["/app/my-app"]

Works flawlessly with debian:

FROM golang:1.15 as prod-build

WORKDIR /app
COPY . .

RUN go mod download
RUN go build -ldflags="-w -s" -o /app/my-app

# runtime container setup
FROM debian:stretch-slim
USER root

WORKDIR /app
COPY --from=prod-build /app/my-app /app/my-app
COPY --from=prod-build /app/resources/ /app/resources

EXPOSE 7575
ENTRYPOINT ["/app/my-app"]

Checklist

Please provide the following information:

  • confluent-kafka-go and librdkafka version (v.1.5.2 and above): go 1.15
  • Apache Kafka broker version: 2.2 and 2.4 both does not work
  • Client configuration: ConfigMap{...}
  • Operating system: MacOS Big Sur
  • Provide client logs (with "debug": ".." as necessary)
  • Provide broker log excerpts
  • Critical issue

I decided to use distroless. Works flawlessly.

FROM golang:1.15 as prod-build

WORKDIR /app
COPY . .

RUN go mod download
RUN go build -ldflags="-w -s" -o /app/my-app

# runtime container setup
FROM gcr.io/distroless/base

WORKDIR /app
COPY --from=prod-build /app/my-app /app/my-app
COPY --from=prod-build /app/resources/ /app/resources

EXPOSE 7575
ENTRYPOINT ["/app/my-app"]

I am not closing the issue since it's still not working with scratch.
Feel free to close if there is no plan/way to make it work.

I decided to use distroless. Works flawlessly.

Thanks so much for sharing this fix, @emretanriverdi !

You're welcome, @respondcreate :)

I am closing this issue, feel free to reopen if needed.