CenturyLinkLabs / dockerfile-from-image

574 stars 134 forks source link

adjust for smaller image #8

Closed ozbillwang closed 8 years ago

ozbillwang commented 9 years ago

The reason we need ruby-dev package is, gem docker-api is native extension.

My approach is to clean the bigger package ruby-dev after gem docker-api get installed, but still need install ruby back.

With this way, the image can be reduced from 46MB to 21MB

$ docker images |grep from
bwits/dockerfile-from-image             latest      f3fabf519fcf   7 minutes ago  21.12 MB
centurylinklabs/dockerfile-from-image   latest      c8fdfe6bfd0d   3 weeks ago    46.01 MB

I did test with this new image on several real images, and get proper result.

ozbillwang commented 9 years ago

ruby-bundler can be cleaned as well. Now it is only 20.23MB.

$ docker images |grep from
bwits/dockerfile-from-image             latest      2bd8621e0eb7    2 minutes ago   20.23 MB
centurylinklabs/dockerfile-from-image   latest      c8fdfe6bfd0d    3 weeks ago     46.01 MB
ozbillwang commented 9 years ago

One more commit (b819707), it can merge the spaces into one.

$ ./dockerfile-from-image.rb redis
ADD file:25e271e77b29ad84681c7580f952b699a33036ca0e40337d124029e5053e86ef in /
CMD ["/bin/bash"]
RUN groupadd -r redis && useradd -r -g redis redis
RUN apt-get update && apt-get install -y --no-install-recommends ca-certificates curl && rm -rf /var/lib/apt/lists/*
RUN gpg --keyserver pool.sks-keyservers.net --recv-keys B42F6819007F00F88E364FD4036A9C25BF357DD4
RUN curl -o /usr/local/bin/gosu -SL "https://github.com/tianon/gosu/releases/download/1.2/gosu-$(dpkg --print-architecture)" && curl -o /usr/local/bin/gosu.asc -SL "https://github.com/tianon/gosu/releases/download/1.2/gosu-$(dpkg --print-architecture).asc" && gpg --verify /usr/local/bin/gosu.asc && rm /usr/local/bin/gosu.asc && chmod +x /usr/local/bin/gosu
ENV REDIS_VERSION=3.0.3
ENV REDIS_DOWNLOAD_URL=http://download.redis.io/releases/redis-3.0.3.tar.gz
ENV REDIS_DOWNLOAD_SHA1=0e2d7707327986ae652df717059354b358b83358
RUN buildDeps='gcc libc6-dev make' && set -x && apt-get update && apt-get install -y $buildDeps --no-install-recommends && rm -rf /var/lib/apt/lists/* && mkdir -p /usr/src/redis && curl -sSL "$REDIS_DOWNLOAD_URL" -o redis.tar.gz && echo "$REDIS_DOWNLOAD_SHA1 *redis.tar.gz" | sha1sum -c - && tar -xzf redis.tar.gz -C /usr/src/redis --strip-components=1 && rm redis.tar.gz && make -C /usr/src/redis && make -C /usr/src/redis install && rm -r /usr/src/redis && apt-get purge -y --auto-remove $buildDeps
RUN mkdir /data && chown redis:redis /data
VOLUME [/data]
WORKDIR /data
COPY file:c4bbead0efd18835c0be64afb728e9d8620af37e52b613e9e34d2be485784d71 in /entrypoint.sh
ENTRYPOINT &{["/entrypoint.sh"]}
EXPOSE 6379/tcp
CMD ["redis-server"]

If compare the old output

ADD file:25e271e77b29ad84681c7580f952b699a33036ca0e40337d124029e5053e86ef in /
CMD ["/bin/bash"]
RUN groupadd -r redis && useradd -r -g redis redis
RUN apt-get update && apt-get install -y --no-install-recommends        ca-certificates         curl    && rm -rf /var/lib/apt/lists/*
RUN gpg --keyserver pool.sks-keyservers.net --recv-keys B42F6819007F00F88E364FD4036A9C25BF357DD4
RUN curl -o /usr/local/bin/gosu -SL "https://github.com/tianon/gosu/releases/download/1.2/gosu-$(dpkg --print-architecture)"    && curl -o /usr/local/bin/gosu.asc -SL "https://github.com/tianon/gosu/releases/download/1.2/gosu-$(dpkg --print-architecture).asc"     && gpg --verify /usr/local/bin/gosu.asc     && rm /usr/local/bin/gosu.asc   && chmod +x /usr/local/bin/gosu
ENV REDIS_VERSION=3.0.3
ENV REDIS_DOWNLOAD_URL=http://download.redis.io/releases/redis-3.0.3.tar.gz
ENV REDIS_DOWNLOAD_SHA1=0e2d7707327986ae652df717059354b358b83358
RUN buildDeps='gcc libc6-dev make'  && set -x   && apt-get update && apt-get install -y $buildDeps --no-install-recommends  && rm -rf /var/lib/apt/lists/*  && mkdir -p /usr/src/redis  && curl -sSL "$REDIS_DOWNLOAD_URL" -o redis.tar.gz  && echo "$REDIS_DOWNLOAD_SHA1 *redis.tar.gz" | sha1sum -c -     && tar -xzf redis.tar.gz -C /usr/src/redis --strip-components=1     && rm redis.tar.gz  && make -C /usr/src/redis   && make -C /usr/src/redis install   && rm -r /usr/src/redis     && apt-get purge -y --auto-remove $buildDeps
RUN mkdir /data && chown redis:redis /data
VOLUME [/data]
WORKDIR /data
COPY file:c4bbead0efd18835c0be64afb728e9d8620af37e52b613e9e34d2be485784d71 in /entrypoint.sh
ENTRYPOINT &{["/entrypoint.sh"]}
EXPOSE 6379/tcp
CMD ["redis-server"]
bdehamer commented 9 years ago

:+1: Looks good to me

ozbillwang commented 9 years ago

nice, waiting for the merge.

bdehamer commented 9 years ago

@davidgardner11 will you pull the trigger on this please

ozbillwang commented 8 years ago

@davidgardner11 & @bdehamer

Can we have this pull request merged now?

davidgardner11 commented 8 years ago

Hi @SydOps -- apologies for the long delay in accepting this PR - I didn't see @bdehamer 's request on Sep 21