[DOCKER] Recommended container image for Python applications

Have you ever wondered which Docker image to choose as the execution environment for your Python application? I tended to decide that I would settle down on the official image after worrying about it every time, so I decided to make a comparison here. I hope it will be helpful to everyone.

Evaluation items for image selection

When choosing an image, I think there are the following perspectives.

Perspective Contents
Stability It is difficult to use it for a long time if the file structure and contents change frequently, so some stability is required.(I don't think there is much)。
Therefore, I would like to use an image that is close to the official one.
Image size The size of the image can be evaluated most quantitatively. The smaller this is, the better.
Security updates Security updates vary by OS distribution, but you need to know how long you will support them.
Is Python installed? You can install it yourself, but it will save you time and build time if it is installed from the beginning.

For major distributions

It is very stable because you can check the stability and the support period of security updates using a standard distribution. However, it also contains many common packages that are not needed to run Python applications, and the image size tends to be large. You also need to install the latest version of Python yourself.

For Alpine Linux

If you want to make the image smaller, alpine-linux may be the first candidate. However, according to the article linked below, it seems that using alpine will eventually cause various problems such as increased image capacity and increased build time. Using Alpine can make Python Docker builds 50× slower

The following is a summary of the content mentioned in the article.

Therefore, alpine has a small raw image size, but it remains uneasy as a Python execution environment.

Docker official Python image

When using Python with Docker, I think many people basically use this image. The types of tags are roughly as follows.

Image type The latest previous tag(2020/As of 03) size Remarks
alpine 3.8.1-alpine3.11 109MB There is an image of Alpine here as well, but it is not recommended due to the disadvantages mentioned above.
buster 3.8.1-buster 933MB An image based on Buster, the latest version of Debian. It's not lightweight because it has many basic packages installed, but it's a good choice for general purpose use.
buster-slim 3.8.1-slim-buster 193MB This is a version in which the common package in the Debian image is omitted and the image size is reduced accordingly. If you only use Python applications, there seems to be no problem.

If you compare the tags, you can see that there is a slim version in addition to the main Debian image. This is an image specialized for executing Python, and it seems that many other functions have been dropped. A note on the python-docker page said, "Use slim if you have strict image size restrictions for Python execution only, and we recommend the default image otherwise." The choice depends on how far you want to run in the container.

Conclusion

From the above considerations, we came to the conclusion that the Docker Image suitable for running Python applications simply is Debian Buster slim. The image size is 198MB, which is quite compact.

Recommended Posts

Recommended container image for Python applications
Personal notes for python image processing
Try docker: Create your own container image for your Python web app
Inject is recommended for DDD in Python
2016-10-30 else for Python3> for:
python [for myself]
python image processing
Recommended for get_or_new
Template for creating command line applications in Python
For new students (Recommended efforts for Python beginners Part 1)
Image processing? The story of starting Python for
Image Processing with Python Environment Setup for Windows
About Python for loops
Image collection Python script for creating datasets for machine learning
Python basics ② for statement
First Python image processing
About Python, for ~ (range)
Image format in Python
python textbook for beginners
Refactoring tools for Python
python for android Toolchain
Image processing with Python
python & jupyterlab container construction
OpenCV for Python beginners
Install Python (for Windows)
[Python] for statement error
Programming with your smartphone anywhere! (Recommended for C / Python)
Python environment for projects
Sample image of Python API server for EC2 (public AMI)
How to implement Python EXE for Windows in Docker container
[AWS Lambda] Use any container Image in Python very simply
[Python] Accessing and cropping image pixels using OpenCV (for beginners)
Image processing with Python (Part 2)
My python data analysis container
Python memo (for myself): Array
About Fabric's support for Python 3
Python list, for statement, dictionary
Python for Data Analysis Chapter 4
Modern Python for intermediate users
Learning flow for Python beginners
Python 3.6 installation procedure [for Windows]
BigQuery integration for Python users
Python learning plan for AI learning
Set Up for Mac (Python)
Python: 3D array image (numpy.array)
Search for strings in Python
Linux distribution recommended for beginners
Python Tkinter notes (for myself)
OpenCV3 installation for Python3 @macOS
Python code memo for yourself
[Python] xmp tag for photos
Sorting image files with Python (2)
Sorting image files with Python (3)
Python environment construction For Mac
Techniques for sorting in Python
CNN (1) for image classification (for beginners)
pp4 (python power for anything)
Image processing with Python (Part 1)
Python3 environment construction (for beginners)
Tweet with image in Python
Sorting image files with Python