In a previous article, I wrote a checklist for running Node.js applications in Docker in a production environment.

Recently, I have been busy developing Python applications. If you compare Node.js and Docker against Python and Docker, you see that many things are the same. But there are differences worth noting as well.

As such, I rewrote my checklist. This one is for running Docker containers with Python in a production environment.

You can find all the examples in this GitHub repository.

1. Choose the Correct Base Image

It’s essential to choose the right base Docker image for your Python application. It depends on the application, but always try to use the official Docker images, as they have excellent documentation, use best practices, and are designed for the most common use cases.

There are still many images to choose from if you look at the official Python Docker images. Most of the time, I choose the image with the smallest size to run my Python app. If you want to run your Python 3.8 app on 64-bit Linux, these are some of the options:

  • python:3.8-buster→883 MB
  • python:3.8-slim-buster → 114 MB
  • python:3.8-alpine → 43 MB

The Docker team based the Alpine images on the Alpine Linux distribution, a minimal Linux distribution with a hardened kernel. If your app works on Alpine, you should use it as your base image, resulting in the smallest image size.

#python #docker #programming #web-development

6 Things To Know When Dockerizing Python Apps in Production
13.55 GEEK