{"id":22108603,"url":"https://github.com/vshloda/docker-python-django-postgres-ssl","last_synced_at":"2026-04-05T22:02:08.502Z","repository":{"id":246423884,"uuid":"820628279","full_name":"vshloda/docker-python-django-postgres-ssl","owner":"vshloda","description":"Setting Up a Django Development Environment Using Docker (docker, python, django, postgres, letsencrypt)","archived":false,"fork":false,"pushed_at":"2024-06-28T22:24:02.000Z","size":29,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-01-29T09:48:52.592Z","etag":null,"topics":["django","docker","letsencrypt","nginx","postgresql","python3"],"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/vshloda.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-26T21:23:54.000Z","updated_at":"2024-06-29T18:03:42.000Z","dependencies_parsed_at":"2024-12-02T01:19:19.653Z","dependency_job_id":null,"html_url":"https://github.com/vshloda/docker-python-django-postgres-ssl","commit_stats":null,"previous_names":["vshloda/docker-python-django-ssl"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vshloda%2Fdocker-python-django-postgres-ssl","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vshloda%2Fdocker-python-django-postgres-ssl/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vshloda%2Fdocker-python-django-postgres-ssl/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vshloda%2Fdocker-python-django-postgres-ssl/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/vshloda","download_url":"https://codeload.github.com/vshloda/docker-python-django-postgres-ssl/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245206459,"owners_count":20577578,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","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":["django","docker","letsencrypt","nginx","postgresql","python3"],"created_at":"2024-12-01T09:16:37.507Z","updated_at":"2025-12-30T23:28:09.680Z","avatar_url":"https://github.com/vshloda.png","language":"Dockerfile","funding_links":[],"categories":[],"sub_categories":[],"readme":"\n## Environment Setup for the Latest Version of Django (Python, Nginx, Postgres) Using Docker\n\n### Project Structure\n\n- `docker` - Folder for Docker configuration files\n- `src` - Folder where the project code will be stored\n- `.env` - Configuration values for the project\n- `docker-compose.yml` - Docker compose configuration file\n- `requirements.txt` - a list of packages or libraries needed to work on a project\n\n### Step-by-Step Guide\n\n#### 1. Environment Setup\n\n- Create a `.env` file based on `.env.example` using the following command:\n\n  ```\n  cp .env.example .env\n  ```\n  \n- Enter or leave the default port values for your project:\n\n    ```\n    DOCKER_HTTP_PORT=80\n    DJANGO_PROJECT_NAME=project  # Project name\n    NGINX_CONF_PATH='./docker/nginx.dev.conf'  # Path to the nginx configuration file,\n                                          # leave as is for the development environment\n    ```\n\n- Fill in the database values:\n\n    ```\n    DB_USER\n    DB_PASSWORD\n    DB_DATABASE\n    DB_HOST\n    DB_PORT\n    ```\n\n#### 2. Build the Project Using Docker Compose\n\n- Run this command\n  \n    ```\n    docker compose build\n    ```\n\n#### 3. Create a Django Project\n\n-  Create a Django project where the project name is \"project\" (if you change the project name, update the DJANGO_PROJECT_NAME in the .env file):\n\n    ```\n    docker compose run --rm web django-admin startproject project .\n    ```\n\n- After running this command, the project code should appear in the src folder.\n\n- You can verify if the project is working by opening the browser and adding the port specified in DOCKER_HTTP_PORT. For example, if it’s set to 80:\n\n  ```\n  http://localhost\n  ```\n\n#### 4. Configure Django \n\n- Import the os library for environment variable handling in settings.py located in the project folder /src/project:\n\n  ```\n  import os\n  ```\n\n- Add STATIC_ROOT in settings.py:\n\n  ```\n  STATIC_ROOT = os.path.join(BASE_DIR, 'static')\n  ```\n  \n- Configure Postgres in settings.py:\n\n  ```\n  DATABASES = {\n      'default': {\n          'ENGINE': 'django.db.backends.postgresql',\n          'HOST': os.environ.get('DB_HOST'),\n          'PORT': os.environ.get('DB_PORT'),\n          'NAME': os.environ.get('DB_DATABASE'),\n          'USER': os.environ.get('DB_USER'),\n          'PASSWORD': os.environ.get('DB_PASSWORD'),\n      }\n  }\n  ```\n\n#### 5. Run Migrations\n\n- Run this command\n  \n  ```\n  docker compose run --rm web python manage.py migrate\n  ```\n\n- After running this command, you can access the admin panel at:\n\n  ```\n  http://localhost/admin\n  ```\n\n#### 6. Handle Static Files\n\n- Uncomment the lines for the ENTRYPOINT in the python.Dockerfile, which runs the command for static files:\n\n  ```\n  COPY ./docker/entrypoint.sh /entrypoint.sh\n  RUN chmod +x /entrypoint.sh\n\n  ENTRYPOINT [\"/entrypoint.sh\"]\n  ```\n\n- Then, restart Docker:\n\n  ```\n  docker compose restart web\n  ```\n- Alternatively, you can run the following command:\n\n  ```\n  docker compose run --rm web python manage.py collectstatic\n  ```\n\n#### 7. If you have a domain for your site and want a free SSL certificate for HTTPS\n\n- Uncomment the service in the docker-compose.yml file:\n\n  ```\n  certbot:\n      image: certbot/certbot    \n      volumes:\n          - ./docker/certbot/www/:/var/www/certbot/:rw\n          - ./docker/certbot/conf/:/etc/letsencrypt/:rw\n  ```\n\n- Uncomment volumes in nginx service in the docker-compose.yml file:\n\n  ```\n  - ./docker/certbot/www:/var/www/certbot:ro\n  - ./docker/certbot/conf:/etc/letsencrypt\n  ```\n- Rebuild and restart the Docker containers using the command:\n\n  ```\n  docker compose up -d --build\n  ```\n- Then run the following command, replacing example.com with your domain:\n\n  ```\n  docker compose run --rm certbot certonly --webroot --webroot-path=/var/www/certbot -d example.com\n  ```\n\n- After this, you need to configure Nginx for HTTPS. To do this, change the value of NGINX_CONF_PATH in the .env file, replacing in file /docker/nginx.prod.conf localhost with your domain:\n\n  ```\n  NGINX_CONF_PATH='./docker/nginx.prod.conf'\n  ```\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvshloda%2Fdocker-python-django-postgres-ssl","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fvshloda%2Fdocker-python-django-postgres-ssl","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvshloda%2Fdocker-python-django-postgres-ssl/lists"}