As we make explicit recommendations on how to best write Dockerfiles for Open edX services, we will capture them here. Here is the current (very incomplete) list:
Use a still-supported Ubuntu LTS base image. Good candidates as of this writing are “ubuntu:focal” and “ubuntu:jammy”.
Explain each installed package with a comment. Each Ubuntu package explicitly installed in the Dockerfile should have a comment before the installation command explaining why that dependency is needed. This can help reveal possible future optimizations which could potentially eliminate some of those dependencies, and minimize “cargo cult” copying into new Dockerfiles which actually don’t need them.
Additionally, here are a few useful reference points to consider:
https://docs.docker.com/develop/develop-images/dockerfile_best-practices/
https://github.com/edx/edx-cookiecutters/blob/master/cookiecutter-django-ida/%7B%7Bcookiecutter.repo_name%7D%7D/Dockerfile (Dockerfile template for new Open edX IDAs)
https://github.com/overhangio/tutor/blob/master/tutor/templates/build/openedx/Dockerfile (Tutor’s Dockerfile for edx-platform)
Note that these don’t all agree on some key points yet. Some decisions yet to be finalized include:
Should the services run in the system Python installation, a venv, a virtualenv, or a pyenv environment? Each option has its pros and cons, and we currently use all of the above in different Dockerfiles.