TDS Archive

An archive of data science, data analytics, data engineering, machine learning, and artificial intelligence writing from the former Towards Data Science Medium publication.

Follow publication

Member-only story

5 easy-to-implement tricks to trim down your Docker image size

Mike Huls
TDS Archive
Published in
6 min readFeb 18, 2022

--

This is a very tiny build! (image by edgeeffectmedia on unsplash)

1. Bundling layers

FROM python:3.9-slim
RUN apt-get update -y
RUN apt-get install some_package
RUN apt-get install some_other_package
FROM python:3.9-slim
RUN apt-get update -y && apt install -y \
package_one \
package_two
# packages:
git, cmake, build-essential, jq, liblua5.2-dev, libboost-all-dev, libprotobuf-dev, libtbb-dev, libstxxl-dev, libbz2-d

2. Avoid installation of unnecessary packages

FROM python:3.9-slim
RUN apt-get update -y && apt install -y --no-install-recommends \
package_one \
package_two
Cleaning up will reduce our image size too (image by jeshoots.com on unsplash)

3. Clean up after install

--

--

TDS Archive
TDS Archive

Published in TDS Archive

An archive of data science, data analytics, data engineering, machine learning, and artificial intelligence writing from the former Towards Data Science Medium publication.

Mike Huls
Mike Huls

Written by Mike Huls

I write about interesting programming-related things: techniques, system architecture, software design and how to apply them in the best way. — mikehuls.com

Responses (1)

Write a response