{"id":18569860,"url":"https://github.com/lcfd/django-dockerfile","last_synced_at":"2026-02-06T03:31:25.105Z","repository":{"id":244829409,"uuid":"816391676","full_name":"lcfd/django-dockerfile","owner":"lcfd","description":"A simple Dockerfile to deploy your Django application 🐳🦄","archived":false,"fork":false,"pushed_at":"2025-01-16T17:51:15.000Z","size":9,"stargazers_count":1,"open_issues_count":1,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-08T15:13:45.876Z","etag":null,"topics":["deployment","django","docker"],"latest_commit_sha":null,"homepage":"","language":"Dockerfile","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/lcfd.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-06-17T16:47:41.000Z","updated_at":"2025-01-16T17:51:17.000Z","dependencies_parsed_at":"2024-09-13T02:36:08.846Z","dependency_job_id":"36db2b78-d015-4605-8d83-98fed1c76053","html_url":"https://github.com/lcfd/django-dockerfile","commit_stats":null,"previous_names":["lcfd/django-dockerfile"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/lcfd/django-dockerfile","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lcfd%2Fdjango-dockerfile","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lcfd%2Fdjango-dockerfile/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lcfd%2Fdjango-dockerfile/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lcfd%2Fdjango-dockerfile/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/lcfd","download_url":"https://codeload.github.com/lcfd/django-dockerfile/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lcfd%2Fdjango-dockerfile/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29148118,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-06T02:39:25.012Z","status":"ssl_error","status_checked_at":"2026-02-06T02:37:22.784Z","response_time":59,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["deployment","django","docker"],"created_at":"2024-11-06T22:35:27.190Z","updated_at":"2026-02-06T03:31:25.082Z","avatar_url":"https://github.com/lcfd.png","language":"Dockerfile","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003ccenter\u003e\n  \u003ch1\u003e\n    Django Dockerfile\n  \u003c/h1\u003e\n\u003c/center\u003e\n\n\u003ccenter\u003e\nA simple repository of configurations\n\u003c/center\u003e\n\n## Why\n\nAfter many years of Django deployments I've decided to collect my knowledge in a single repository.\nIt's a living configuration and is the reflection of the tools I'm using to deploy my applications.\n\nAnyway I the goal is to break down all the piece needed to deploy Django and document them so any piece can be used—as much as possible—everywhere.\n\nAny feedback is welcome.\n\n## Good to know\n\n- Static and media files are hosted and served directly from the hosting machine\n- Caddy leaves in the same container of Django—check the Dockerfile\n- The base Docker image for Django is `3.12-slim`\n\n## Setup in your project\n\n- Copy `Dockerfile`, `Caddyfile` and `.dockerignore` in your Django project\n  - It should be the same place of `pyproject.toml`\n- Set the `static` and `media` config variables in the Django's `settings.py` file\n\n## Environment Variables\n\nThose variables are for production. They are used in the below settings.\n\n```bash\n# 1 = init service.\n# 0 = after the first service, for horizontal deployments\n# For example: start.sh will run migrations\nIS_INIT=1\n\nDEBUG=False\n\nAPP_NAME=yourname\n\nALLOWED_HOSTS=*\nCSRF_TRUSTED_ORIGINS=https://*.mydomain.com\nCORS_ALLOWED_ORIGINS=https://...\n# CSRF_COOKIE_DOMAIN=.yourdomain.xyz\nDATABASE_URL=postgres://asdfasdf:asdfasdf:5432/postgres\nSECRET_KEY=asdfasdfasdfasdfasdfasdf\n\n# Superuser\nDJANGO_SUPERUSER_EMAIL=your@superuser.email\nDJANGO_SUPERUSER_PASSWORD=password\nDJANGO_SUPERUSER_USERNAME=username\n\nLANGUAGE_CODE=en-us\nTIME_ZONE=\"UTC\"\nMEDIA_URL=media/\nSTATIC_URL=static/\n# MEDIA_ROOT=path\n# STATIC_ROOT=path\n\nSESSION_COOKIE_SECURE=False\nCSRF_COOKIE_SECURE=False\nSECURE_SSL_REDIRECT=False\n\nEMAIL_HOST=localhost\nEMAIL_PORT=25\nEMAIL_HOST_USER=\nEMAIL_HOST_PASSWORD=\nEMAIL_USE_TLS=False\nSERVER_EMAIL=root@localhost\nDEFAULT_FROM_EMAIL=django@localhost\n```\n\n### Django settings\n\nI suggest you to:\n\n- Install [django-environ](https://github.com/joke2k/django-environ)\n- Copy and paste those settings chunk by chunk and not all at the same time.\n- Read [Django docs for production](https://docs.djangoproject.com/en/5.0/howto/deployment/checklist/#critical-settings)\n\n```python\nimport environ\n\nenv = environ.Env(\n    DEBUG=(bool, False),\n    APP_NAME=(str, \"APPNAME\"),\n    ALLOWED_HOSTS=(list[str], [\"*\"]),\n    SECRET_KEY=(str, \"asdfasdfasdfasdfasdfasdf\"),\n    CSRF_TRUSTED_ORIGINS=(list[str], []),\n    CORS_ALLOWED_ORIGINS=(list[str], []),\n    DATABASE_URL=(str, False),\n    LANGUAGE_CODE=(str, \"en-us\"),\n    TIME_ZONE=(str, \"UTC\"),\n    MEDIA_ROOT=(str, BASE_DIR / \"media\"),\n    MEDIA_URL=(str, \"media/\"),\n    STATIC_URL=(str, \"static/\"),\n    STATIC_ROOT=(str, BASE_DIR / \"static\"),\n    SESSION_COOKIE_SECURE=(bool, False),\n    CSRF_COOKIE_SECURE=(bool, False),\n    CSRF_COOKIE_DOMAIN=(str, None),\n    SECURE_SSL_REDIRECT=(bool, False),\n    EMAIL_HOST=(str, \"localhost\"),\n    EMAIL_PORT=(int, 25),\n    EMAIL_HOST_USER=(str, \"\"),\n    EMAIL_HOST_PASSWORD=(str, \"\"),\n    EMAIL_USE_TLS=(bool, False),\n    SERVER_EMAIL=(str, \"root@localhost\"),\n    DEFAULT_FROM_EMAIL=(str, \"django@localhost\"),\n)\n\n# Usage\n\nDEBUG = env(\"DEBUG\")\nAPP_NAME = env(\"APP_NAME\")\nSECRET_KEY = env(\"SECRET_KEY\")\nALLOWED_HOSTS = env.list(\"ALLOWED_HOSTS\")\nCSRF_TRUSTED_ORIGINS = env.list(\"CSRF_TRUSTED_ORIGINS\")\n\ndatabase_url = env(\"DATABASE_URL\")\n\nif database_url:\n    DATABASES = {\n        \"default\": env.db(),\n    }\nelse:\n    DATABASES = {\n        \"default\": {\n            \"ENGINE\": \"django.db.backends.sqlite3\",\n            \"NAME\": BASE_DIR / 'db.sqlite3'\n        }\n    }\n\nLANGUAGE_CODE = env(\"LANGUAGE_CODE\")\nTIME_ZONE = env(\"TIME_ZONE\")\n\nMEDIA_ROOT = env(\"MEDIA_ROOT\")\nMEDIA_URL = env(\"MEDIA_URL\")\nSTATIC_URL = env(\"STATIC_URL\")\nSTATIC_ROOT = env(\"STATIC_ROOT\")\n\nSESSION_COOKIE_SECURE = env(\"SESSION_COOKIE_SECURE\")\nCSRF_COOKIE_SECURE = env(\"CSRF_COOKIE_SECURE\")\n# I used it for subdomains on the same domain\nCSRF_COOKIE_DOMAIN = env(\"CSRF_COOKIE_DOMAIN\")\n\nSECURE_SSL_REDIRECT = env(\"SECURE_SSL_REDIRECT\")\n\nEMAIL_HOST = env(\"EMAIL_HOST\")\nEMAIL_PORT = env(\"EMAIL_PORT\")\nEMAIL_HOST_USER = env(\"EMAIL_HOST_USER\")\nEMAIL_HOST_PASSWORD = env(\"EMAIL_HOST_PASSWORD\")\nEMAIL_USE_TLS = env(\"EMAIL_USE_TLS\")\nSERVER_EMAIL = env(\"SERVER_EMAIL\")\nDEFAULT_FROM_EMAIL = env(\"DEFAULT_FROM_EMAIL\")\n```\n\n## On Coolify\n\nYour project will be exposed on the `8001` port by Caddy.\n\n- In `Ports Mappings` set `your_port:8001`\n- In `Ports Exposes` set `8001`.\n\n### Domain and Ports\n\nSet your domain in `Domains`.\nSet `Ports Exposes` with the port number used by Caddy.\n\n### Volumes\n\nIf you are storing uploaded files ([media files](https://docs.djangoproject.com/en/5.1/topics/files/)) on the filesystem you need a Docker volume.\n\n1. Go to `Storages`\n2. `+ Add` to create new volumes\n3. Add one volume for `media` with `Destination Path` set to `/project/media`\n\n### Env variables\n\n1. Go to the `Environment Variables` tab of your service configuration\n2. Set the variables seen above\n\n### Database\n\nCreate a new service using `postgresql`.\nThe containers will be on the same network so the the configurations in the `Environment Variables` section should work right away.\n\n**Remember** to use the password provided in the General tab.\n\n### Build\n\nIf your Django project leves in a subfolder of the repository:\n\n- Set `Base Directory` to: `/your-folder-name`\n- Set `Dockerfile Location` to: `/Dockerfile` (assuming that it's at the root of your project)\n- Set `Watch Paths` to: `your-folder-name/*`\n\n## Extra\n\n#### Useful commands for automated tasks\n\n- `python manage.py createsuperuser --noinput`\n- `python manage.py collectstatic --noinput`\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flcfd%2Fdjango-dockerfile","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flcfd%2Fdjango-dockerfile","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flcfd%2Fdjango-dockerfile/lists"}