Docker container allowing you to build and test your Python project.
This container mainly targets Python web project developments (Understand Django) but you can try to make it work with your project even if your project is not using web technologies.
Extended from official Python image for Docker.
pip - The PyPA recommended tool for installing Python packages.poetry - Python packaging and dependency management made easyuv - An extremely fast Python package and project manager, written in Rust.We recommend you to use the dev user instead of root when running that container.
The container's working directory is /var/www/app so we advise you to mount your project directory onto this place.
docker-compose.yml
services:
django:
container_name: my-super-django-app
build:
dockerfile: ./docker/django/Dockerfile
context: .
environment:
PYTHONUNBUFFERED: 1
ports:
- "8000:8000"
entrypoint: ./docker/django-entrypoint.sh
volumes:
- ./:/var/www/app
- ./log:/var/log/django/
./docker/django-entrypoint.sh
#!/usr/bin/env bash
poetry install
poetry run python manage.py migrate
poetry run python manage.py loaddata fixtures/groups.yaml
poetry run python manage.py loaddata fixtures/transaction_types.yaml
poetry run python manage.py loaddata fixtures/wallet_types.yaml
poetry run python manage.py collectstatic --noinput
export LOG_HANDLER='file'
poetry run python manage.py runserver 0.0.0.0:8000
./docker/django/Dockerfile
FROM vnvsa/python:3.12
USER root
# Install system deps (cron and sudo are already included in the base image)
RUN apt-get update --yes && \
apt-get install --yes \
unixodbc \
unixodbc-dev \
wget
# Install python deps
RUN pip install --upgrade pip && \
pip install pyodbc && \
mkdir -p /var/log/django/ && \
chown dev:dev /var/log/django/
USER dev
Run using a compose configuration:
docker compose run --entrypoint="poetry up --latest" django
The container includes cron for running scheduled tasks (useful for django-crontab and similar tools). The dev user can start cron using sudo without a password.
Create a supervisord configuration file to manage cron alongside your application:
./docker/supervisord.conf
[supervisord]
nodaemon=true
logfile=/tmp/supervisord.log
pidfile=/tmp/supervisord.pid
[program:cron]
command=/usr/bin/sudo /usr/sbin/cron -f
autostart=true
autorestart=true
stdout_logfile=/tmp/cron.log
stderr_logfile=/tmp/cron_err.log
priority=1
[program:django]
command=poetry run python manage.py runserver 0.0.0.0:8000
autostart=true
autorestart=true
stdout_logfile=/tmp/django.log
stderr_logfile=/tmp/django_err.log
directory=/var/www/app
Update your entrypoint to use supervisord:
./docker/django-entrypoint.sh
#!/usr/bin/env bash
poetry install
poetry run python manage.py migrate
poetry run python manage.py collectstatic --noinput
# Add Django crontab jobs
poetry run python manage.py crontab add
# Start supervisord
supervisord -c /var/www/app/docker/supervisord.conf
If you prefer to start cron manually:
# Start cron service
sudo service cron start
# Add your crontab
crontab my-crontab-file
# Or for django-crontab
python manage.py crontab add
Update your Dockerfile to install the version of poetry you need.
FROM vnvsa/python:3.12
USER root
RUN pip install poetry==1.8.3 \
&& pip cache purge
USER dev
Pull requests, bug reports, and feature requests are welcome.
MIT License. See the LICENSE file.
Content type
Image
Digest
sha256:f658231ce…
Size
523.1 MB
Last updated
4 days ago
docker pull vnvsa/python:3.14-trixie