Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reduce Docker image size from 165 MB to 32.8 MB #131

Merged
merged 3 commits into from
Aug 27, 2018

Conversation

cbliard
Copy link
Contributor

@cbliard cbliard commented Aug 23, 2018

I recently upgraded from the old edgurgelpoxa:0.5.0 docker image to the latest edgurgel:poxa-automated:0.7.2 docker image, and the image size grew from 26 MB to 165 MB.

I tried to reduce the size by using multi-stage build available from Docker 17.05 to avoid having any
build artifacts at all and no git package installed. I managed to get a 114 MB image.

I also used apk --no-cache instead of apk --update .... && rm -rf /var/cache/apk/*.

I do not know Erlang/Elixir well enough to go further but at least it's 50 MB less.

Using multi-stage build available from Docker 17.05 to avoid having any
build artifacts.
@cbliard
Copy link
Contributor Author

cbliard commented Aug 23, 2018

Also I noticed that the version referenced in mix.exs is 0.7.1. Shouldn't it be 0.7.2?

@cbliard
Copy link
Contributor Author

cbliard commented Aug 23, 2018

I tried another approach were the final size is 36 MB, but I'm not sure if it runs correctly. I have modified rel/config.exs to include erts. In distillery docs, it says it "Will ensure that the Erlang Runtime System is included in the release", so it is like a statically linked app.

I then untar the release tar.gz in /app and at next build stage I only copy this directory to a blank alpine image. I only installed openssl and bash packages in this image.

Do you think it can work like this?

@edgurgel
Copy link
Owner

Thank you so much for the PR! I will pull your branch this weekend and if it's all working well I will release a new version! That's awesome 🎉

Dockerfile Outdated
@@ -13,7 +13,18 @@ RUN mix deps.get
RUN mix compile
RUN echo "" > config/poxa.prod.conf
RUN mix release
RUN mkdir -p /app/$APP_NAME
WORKDIR /app/$APP_NAME
RUN tar xzf /source/_build/prod/rel/$APP_NAME/releases/0.7.1/$APP_NAME.tar.gz
Copy link
Owner

@edgurgel edgurgel Aug 26, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we need to tar the rel/* so that we don't need to hardcode the version here.

I've tested and it's working nicely! I got 32.8MB here 🎉

@cbliard
Copy link
Contributor Author

cbliard commented Aug 27, 2018

Good point! I replaced 0.7.1 by * so the version is not hardcoded anymore.

I'm glad it works :-) I took inspiration from this elixir-forum thread and especially this comment but I was not sure that omitting erlang-xmerl erlang-crypto erlang-sasl packages would work in the final image.

Should I stash the commits?

@cbliard cbliard changed the title Reduce Docker image size from 165 MB to 115 MB Reduce Docker image size from 165 MB to 32.8 MB Aug 27, 2018
@edgurgel
Copy link
Owner

@cbliard, thank you so much! I will release a new version soon! 👌

The commits are ok! I can squash & merge no problem 👍

@cbliard
Copy link
Contributor Author

cbliard commented Aug 27, 2018

Perfect! Happy to help :-) Thanks for providing poxa 👍

@edgurgel edgurgel merged commit 4c1c852 into edgurgel:master Aug 27, 2018
@edgurgel
Copy link
Owner

Awesome! I will do some manual testing later today or tomorrow and release a brand new version. Thanks once again 👍

@edgurgel
Copy link
Owner

edgurgel_poxa-automated_-_docker_hub

The latest image is looking good 👍

@cbliard
Copy link
Contributor Author

cbliard commented Aug 29, 2018

Great 🎉

I'm waiting for the v0.x.x docker image release :-)

@cbliard cbliard deleted the reduce-docker-img-size branch August 29, 2018 11:38
@edgurgel
Copy link
Owner

edgurgel commented Sep 3, 2018

0.8.0 is out! I also updated the heroku deployment! Thanks again!

@cbliard
Copy link
Contributor Author

cbliard commented Sep 3, 2018

👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants