Sign inSign up

vnvsa/python

By vnvsa

Updated 4 days ago

Image
0

10K+

vnvsa/python repository overview

Python container (Docker container for Python web development)

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.

Tools installed
  • pip - The PyPA recommended tool for installing Python packages.
  • poetry - Python packaging and dependency management made easy
  • uv - An extremely fast Python package and project manager, written in Rust.
Dependencies installed

Supported versions:

Debian
  • Bullseye
  • Bookworm
Python
  • 3.10
  • 3.11
  • 3.12
  • 3.13

Use the container

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
Poetry up

Run using a compose configuration:

docker compose run --entrypoint="poetry up --latest" django
Using cron for scheduled tasks

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
Manual cron start

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
Troubleshooting
Poetry version is too recent

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

Contributing

Pull requests, bug reports, and feature requests are welcome.

Contacts

License

MIT License. See the LICENSE file.

Tag summary

Content type

Image

Digest

sha256:f658231ce

Size

523.1 MB

Last updated

4 days ago

docker pull vnvsa/python:3.14-trixie