All Projects → erroneousboat → Docker Django

erroneousboat / Docker Django

Licence: mit
A project to get you started with Docker and Django.

Programming Languages

python
139335 projects - #7 most used programming language

Projects that are alternatives of or similar to Docker Django

Docker Django Nginx Uwsgi Postgres Tutorial
Docker + Django + Nginx + uWSGI + Postgres 基本教學 - 從無到有 ( Docker + Django + Nginx + uWSGI + Postgres Tutorial )
Stars: ✭ 334 (+96.47%)
Mutual labels:  postgresql, django, uwsgi, nginx
Autoops
linux资产管理,cmdb,django, webssh,运维管理平台,数据库操作平台 本项目已停止开发!因长时间未对代码进行维护,可能会造成项目在不同环境上无法部署、运行BUG等问题,请知晓!项目仅供参考!
Stars: ✭ 340 (+100%)
Mutual labels:  django, uwsgi, nginx
Hydroshare
HydroShare is a collaborative website for better access to data and models in the hydrologic sciences.
Stars: ✭ 117 (-31.18%)
Mutual labels:  postgresql, django, nginx
Django React Boilerplate
DIY Django + React Boilerplate for starting your SaaS
Stars: ✭ 385 (+126.47%)
Mutual labels:  postgresql, django, nginx
Docker Nginx Postgres Django Example
Example using Docker, Django, multiple Postgres databases, NginX, Gunicorn, pipenv, GitLab CI and tox.
Stars: ✭ 110 (-35.29%)
Mutual labels:  postgresql, django, nginx
Opman Django
💯✅自动化运维平台:CMDB、CI/CD、DevOps、资产管理、任务编排、持续交付、系统监控、运维管理、配置管理
Stars: ✭ 539 (+217.06%)
Mutual labels:  django, uwsgi, nginx
Python Microservice Fastapi
Learn to build your own microservice using Python and FastAPI
Stars: ✭ 96 (-43.53%)
Mutual labels:  postgresql, nginx
Docker Laravel
🐳 Docker Images for Laravel development
Stars: ✭ 101 (-40.59%)
Mutual labels:  postgresql, nginx
Pyblog
Pyblog 是一个简单易用的在线 Markdown 博客系统,它使用 Python 的 flask 架构,理论上支持所有 flask-sqlalchemy 所能支持的数据库。 编辑器使用的是 editor.md。当前版本(v2.0)支持且仅支持 python3! Python 的 Markdown to HTML 编译器使用的是 Mistune! Just so!
Stars: ✭ 113 (-33.53%)
Mutual labels:  uwsgi, nginx
Symfony 4 Docker Env
Docker Environment for Symfony. PHP-FPM, NGINX SSL Proxy, MySQL, LEMP
Stars: ✭ 119 (-30%)
Mutual labels:  postgresql, nginx
Dockerized Flask
Dockerized web app using NGINX, Flask and PostgreSQL
Stars: ✭ 119 (-30%)
Mutual labels:  postgresql, nginx
W3develops
The w3develops.org open source codebase - Learn, build, and meetup with other developers on DISCORD https://discord.gg/WphGvTT and YOUTUBE http://bit.ly/codingyt
Stars: ✭ 120 (-29.41%)
Mutual labels:  postgresql, django
Shorty
🔗 A URL shortening service built using Flask and MySQL
Stars: ✭ 78 (-54.12%)
Mutual labels:  uwsgi, nginx
Generic django project
starting point for a new Django site (with FeinCMS, deployable on Nginx using Fabric)
Stars: ✭ 76 (-55.29%)
Mutual labels:  django, nginx
Flask Restful Authentication
An example for RESTful authentication using nginx, uWSGI, Flask, MongoDB and JSON Web Token(JWT).
Stars: ✭ 63 (-62.94%)
Mutual labels:  uwsgi, nginx
Django Tsvector Field
Django field for tsvector (PostgreSQL full text search vector) with managed stored procedure and triggers.
Stars: ✭ 56 (-67.06%)
Mutual labels:  postgresql, django
Vms
THIS PROJECT IS ARCHIVED. Volunteer Management System.
Stars: ✭ 127 (-25.29%)
Mutual labels:  postgresql, django
Django Init
Project template used at Fueled for scaffolding new Django based projects. 💫
Stars: ✭ 126 (-25.88%)
Mutual labels:  django, uwsgi
Dailyfresh
Django-天天生鲜电商学习项目
Stars: ✭ 127 (-25.29%)
Mutual labels:  django, nginx
Django Celery Docker Example
Example Docker setup for a Django app behind an Nginx proxy with Celery workers
Stars: ✭ 149 (-12.35%)
Mutual labels:  django, nginx

Docker Django

tl;dr

$ git clone [email protected]:erroneousboat/docker-django.git
$ docker-compose up

Now you can access the application at https://localhost and the admin site at https://localhost/admin.

A project to get you started with Docker and Django. This is made to serve as an example for you to hack on, so I don't claim that this is the correct way to setup a system with Django and Docker. Thus, I advice to also look at other projects.

Stack and version numbers used:

Name Version
Django 2.1.4
Nginx 1.15
Postgresql 11.1
uWSGI 2.0.17.1

Folder structure

$ tree -L 1 --dirsfirst
.
├── config              # files needed for configuration
├── webapp              # actual webapp
├── docker-compose.yml  # docker-compose setup with container orchestration instructions
├── LICENSE             # license for this project
└── README.md           # this file

Setting up

Docker

See installation instructions at: docker documentation

Docker Compose

Install docker compose, see installation instructions at https://docs.docker.com/compose/install/

Django

Create django project in the webapp folder or copy a project to the webapp folder or use the sample project enclosed in this project and go directly to the section 'Fire it up':

# Be sure you have Django installed on your system
$ django-admin startproject <name_project>

Edit config/environment/development.env file and add the name of your project at DJANGO_PROJECT_NAME or just leave it as is to start the default application.

Edit the settings.py file with the correct database credentials and static root:

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.postgresql_psycopg2',
        'NAME': os.environ.get('POSTGRES_NAME'),
        'USER': os.environ.get('POSTGRES_USER'),
        'PASSWORD': os.environ.get('POSTGRES_PASSWORD'),
        'HOST': os.environ.get('POSTGRES_HOST'),
        'PORT': os.environ.get('POSTGRES_PORT'),
    }
}

STATIC_ROOT = '/srv/static-files'

Environment variables

The file config/environment/development.env contains the environment variables needed in the containers. You can edit this as you see fit, and at the moment these are the defaults that this project uses. However when you intend to use this, keep in mind that you should keep this file out of version control as it can hold sensitive information regarding your project. The file itself will contain some commentary on how a variable will be used in the container.

Fire it up

Start the container by issuing one of the following commands:

$ docker-compose up             # run in foreground
$ docker-compose up -d          # run in background

Other commands

Build images:

$ docker-compose build
$ docker-compose build --no-cache       # build without cache

See processes:

$ docker-compose ps                 # docker-compose processes
$ docker ps -a                      # docker processes (sometimes needed)
$ docker stats [container name]     # see live docker container metrics

See logs:

# See logs of all services
$ docker-compose logs

# See logs of a specific service
$ docker-compose logs -f [service_name]

Run commands in container:

# Name of service is the name you gave it in the docker-compose.yml
$ docker-compose run [service_name] /bin/bash
$ docker-compose run [service_name] python /srv/starter/manage.py shell
$ docker-compose run [service_name] env

Remove all docker containers:

docker rm $(docker ps -a -q)

Remove all docker images:

docker rmi $(docker images -q)

Some commands for managing the webapp

To initiate a command in an existing running container use the docker exec command.

# Find container_name by using docker-compose ps

# restart uwsgi in a running container.
$ docker exec [container_name] touch /etc/uwsgi/reload-uwsgi.ini

# create migration file for an app
$ docker exec -it [container-name] \
    python /srv/[project-name]/manage.py makemigrations scheduler

# migrate
$ docker exec -it [container-name] \
    python3 /srv/[project-name]/manage.py migrate

# get sql contents of a migration
$ docker exec -it [container-name] \
    python3 /srv/[project-name]/manage.py sqlmigrate [appname] 0001

# get to interactive console
$ docker exec -it [container-name] \
    python3 /srv/[project-name]/manage.py shell

# testing
docker exec [container-name] \
    python3 /srv/[project-name]/manage.py test

Troubleshooting

Q: I get the following error message when using the docker command:

FATA[0000] Get http:///var/run/docker.sock/v1.16/containers/json: dial unix /var/run/docker.sock: permission denied. Are you trying to connect to a TLS-enabled daemon without TLS? 

A: Add yourself (user) to the docker group, remember to re-log after!

$ usermod -a -G docker <your_username>
$ service docker restart

Q: Changes in my code are not being updated despite using volumes.

A: Remember to restart uWSGI for the changes to take effect.

# Find container_name by using docker-compose ps
$ docker exec [container_name] touch /etc/uwsgi/reload-uwsgi.ini
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].