Created
April 23, 2020 04:17
-
-
Save jaihind213/e82d41dc79f52cfa64ca32350bdb27df to your computer and use it in GitHub Desktop.
Install librdkafka in alpine docker
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks! This was very helpful