Skip to content

Instantly share code, notes, and snippets.

@jaihind213
Created April 23, 2020 04:17
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jaihind213/e82d41dc79f52cfa64ca32350bdb27df to your computer and use it in GitHub Desktop.
Save jaihind213/e82d41dc79f52cfa64ca32350bdb27df to your computer and use it in GitHub Desktop.
Install librdkafka in alpine docker
FROM alpine:3.9
ENV LIBRD_VER=1.3.0
WORKDIR /tmp
#vishnus-MacBook-Pro:librd vrao$ docker images |grep lib
#lib proper_cleanup 675073279e9c 4 seconds ago 53.3MB
#lib cleanup 7456af7df73b 2 minutes ago 218MB
#lib simple 9724aed9519c 7 minutes ago 342MB
######### simple install ################# -> 342MB
#RUN apk add --no-cache --virtual .make-deps bash make wget git gcc g++ && apk add --no-cache musl-dev zlib-dev openssl zstd-dev pkgconfig libc-dev
#RUN wget https://github.com/edenhill/librdkafka/archive/v${LIBRD_VER}.tar.gz
#RUN tar -xvf v${LIBRD_VER}.tar.gz && cd librdkafka-${LIBRD_VER} && ./configure --prefix /usr && make && make install
##########################################
######### cleanup deps ################ -> 218 MB
#RUN apk add --no-cache --virtual .make-deps bash make wget git gcc g++ && apk add --no-cache musl-dev zlib-dev openssl zstd-dev pkgconfig libc-dev
#RUN wget https://github.com/edenhill/librdkafka/archive/v${LIBRD_VER}.tar.gz
#RUN tar -xvf v1.3.0.tar.gz && cd librdkafka-${LIBRD_VER} && ./configure --prefix /usr && make && make install && make clean
#RUN rm -rf librdkafka-${LIBRD_VER} && rm -rf v${LIBRD_VER}.tar.gz && apk del .make-deps
##########################################
######### optimised Size with proper cleanup #################
# U need to install deps, build the library, and uninstall the deps in single command so that image size not polluted by these deps, example: if you run 'apk del' as separate RUN command , size does not reduce.
# as docker works on concepts on layers, each run adds to layers and u cant delete prev layer -> https://github.com/gliderlabs/docker-alpine/issues/186
# so we need to install deps, build librd kafka and then uninstall/cleanup the deps in single command to keep size less.
# Size of docker image > 250 MB without this logic, with this logic ~53MB
# for debugging run separately each command instead of anding them.
RUN apk add --no-cache --virtual .make-deps bash make wget git gcc g++ && apk add --no-cache musl-dev zlib-dev openssl zstd-dev pkgconfig libc-dev && wget https://github.com/edenhill/librdkafka/archive/v${LIBRD_VER}.tar.gz && tar -xvf v${LIBRD_VER}.tar.gz && cd librdkafka-${LIBRD_VER} && ./configure --prefix /usr && make && make install && make clean && rm -rf librdkafka-${LIBRD_VER} && rm -rf v${LIBRD_VER}.tar.gz && apk del .make-deps
################################################################
RUN export PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/lib/pkgconfig/
ENV PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/lib/pkgconfig/
@enricodvn
Copy link

Thanks! This was very helpful

@bytespireio
Copy link

@enricodvn i have not enabled kerberos/gsapi before. what error are u getting

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment