Categories
Containerisation Django Docker Podman Python

Django migrations inside a Docker container

The easiest way to have Django run a migration inside a Docker container is to get Docker to run a new container to perform the task.

Using ‘run’ instead of ‘exec’ works if there is a start-up script like entrypoint.sh that prevents the container from starting until the migration has been completed (egg-chicken-egg).

E.g. I have a Django app called ‘web’ defined in docker-compose.yml , my terminal’s current working directory is the Django container folder where manage.py is resident.

$ docker compose run web ./manage.py migrate

This probably works similarly with Podman, I just haven’t tried it yet to verify.

Privacy Preference Center

      Necessary

      Advertising

      Analytics

      Other