Use --no-install-recommends in dockerfiles
Anywhere we use apt-get install in our Dockerfiles, we should also add --no-install-recommends. According to https://ubuntu.com/blog/we-reduced-our-docker-images-by-60-with-no-install-recommends this creates smaller images which build faster. Note:
It is important to keep in mind that doing this could result in some missing libraries in your projects which you may have to add back explicitly, but this will ultimately give you more control in the dependencies in your project.
Hey @guyjeangilles, It seems like a good fix. Can I work on it?
Go for it @Kaushl2208! :)
If someone wants to try adding these tags and build new images + see if anything breaks, that would be a great fist step
I realized I forgot to share my write up of trying this out on the two apt-get lines in docker/Dockerfile.olbase that currently lack --no-install-recommends. How embarrassing!
The short of it is that the savings were fairly modest.
Results of adding --no-install-recommends the first apt-get line (line 17 of Dockrefile.olbase)
Sizes
- Before:
<missing> 3 weeks ago /bin/sh -c apt-get -qq update && apt-get ins… 727MB - After :
5dcd206fa807 29 minutes ago /bin/sh -c apt-get -qq update && apt-get ins… 624MB
Site status
- It seems to work.
- Webpack appears to compile things properly. (
docker-compose run --rm web npm run watch) - I can search for a book (Flatland), find it, and look at the entry.
- I can also mark it as 'Want to Read', visit my reading log, see it, and find it there with a search for "flat*", etc.
Results of adding --no-install-recommends the apt-get install -y nodejs line (line 39 of Dockrefile.olbase)
Sizes
- Before:
<missing> 3 weeks ago /bin/sh -c apt-get update && apt-get install… 10.6MB - After :
<missing> 7 minutes ago /bin/sh -c apt-get update && apt-get -y inst… 10.1MB
Site status
- It seems to work.
- Webpack appears to compile things properly. (
docker-compose run --rm web npm run watch) - I can search for a book (Flatland), find it, and look at the entry.
- I can also mark it as 'Want to Read', visit my reading log, see it, and find it there with a search for "flat*", etc.
APT packages
I also tried using the 'no-x' version of vim and emacs:
- Without -nox on the editors: 606MB
- With -nox 543MB
Total savings, including use of -nox versions of the editors: 166MB.
@mekarpeles
can i work on this issue
Hi @scottbarnes @cdrini I’d like to pick up #2656. I’ll grep all Dockerfiles for apt-get install, add --no-install-recommends where missing, then build the dev/base images locally and share logs + a homepage screenshot as in RayBB’s note on #11904. OK to proceed?