Docker Essentials — Image Optimization

Optimize your Docker images for production deployment.

alpha2phi
5 min readNov 4, 2021
Essential Docker Tips and Tricks

Overview

Regardless of your role as a developer, sysadmin, or data scientist, Docker should be no stranger to you. In this article, let’s explore how we can optimize a Python Django-based application image from >400 MB to < 30 MB for production deployment.

The guidelines should apply to other programming languages, front-end or back-end frameworks you choose to build an application.

Setting up a Django-based App

Let’s start by setting up a Django-based app.

You can easily create a Django application following the documentation.

$ django-admin startproject django_slim

A project with the following structure is created.

django_slim/
manage.py
django_slim/
__init__.py
settings.py
urls.py
asgi.py
wsgi.py

requirements.txt

I am going to use Uvicorn with Gunicorn to start up the application. Let’s create a requirements.txt file with the following content.

Django
uvicorn
gunicorn

Dockerfile Without…

--

--

alpha2phi
alpha2phi

Written by alpha2phi

Software engineer, Data Science and ML practitioner.

No responses yet