Docker images can easily get to 2–3GB. Here’s some tips that can help reduce their sizes. Tip #1 — Use a smaller base image FROM ubuntu will set you to 128MB on the outset. Consider using a smaller base image. For each or line you add in your you will be increasing the size of the image by that library size. Realize that you probably don’t need many of those libraries you are installing. apt-get install yum install Dockerfile Consider using an base image (only 5MB in size). Most likely, there are alpine tags for the programming language you are using. For example, Python has (~50MB) and (~65MB). alpine 2.7-alpine 3.5-alpine Tip #2 — Don’t install debug tools like vim/curl I notice many developers install and in their so that they can more easily debug their application. Unless your application depends on it, don’t install those dependencies. Doing so defeats the purpose of using a small base image. vim curl Dockerfile But how do I debug? One technique is to have a development Dockerfile and a production Dockerfile. During development, have all of the tools you need, and then when deploying to production remove the development tools. Tip #3 — Minimize Layers Each line of a is a step in the build process; a layer that takes up size. Combine your RUN statements to reduce the image size. Instead of Dockerfile FROM debianRUN apt-get install -y <packageA>RUN apt-get install -y <packageB> Do FROM debianRUN apt-get install -y <packageA> <packageB> A drawback of this approach is that you’ll have to rebuild the entire image each time you add a new library. If you aren’t aware, Docker doesn’t rebuild layers it’s already built, and it caches the line by line Try changing one character of a you’ve already built, and then rebuild. You’ll notice that each step above that line will be recognized as already been built, but the line you changed (and each line following) will be rebuilt. Dockerfile Dockerfile A strategy I recommend is that while in development and testing dependencies, separate out the commands. Once you’re ready to deploy to production, combine the statements into one line. RUN RUN Tip #4 Use — no-install-recommends on apt-get install Adding to can help dramatically reduce the size by avoiding installing packages that aren’t technically dependencies but are recommended to be installed alongside packages. — no-install-recommends apt-get install -y commands should have added. apk add --no-cache Tip #5 Add rm -rf / /lib/apt/lists_/* to same layer as apt-get installs_ var Add at the end of the to clean up after install packages. rm -rf /**var**/lib/apt/lists/* apt-get -y install For , add yum yum clean all Also, if you are install or in order to download some package, remember to combine them all in one statement. Then at the end of the run statement, or once you no longer need them. This advice goes for any package that you only need temporarily. wget curl RUN apt-get remove curl wget Tip #6 Use FromLatest.io will Lint your Dockerfile and check for even more steps you can perform to reduce your image size. FromLatest There are many other tips out there. Feel free to share any that I may of missed. is how hackers start their afternoons. We’re a part of the family. We are now and happy to opportunities. Hacker Noon @AMI accepting submissions discuss advertising & sponsorship To learn more, , , or simply, read our about page like/message us on Facebook tweet/DM @HackerNoon. If you enjoyed this story, we recommend reading our and . Until next time, don’t take the realities of the world for granted! latest tech stories trending tech stories