This is an sample of building a Django environment on Docker using Nginx, Gunicorn, and PostgreSQL.
$ git clone git@github.com:dsonoda/django-on-docker.git
Use docker-compose to set up a service-specific container on a single host to build a Django web application development environment. The host is assumed to be in a local environment.
SECRET_KEY=[django secret key value]
DB_PASSWORD=[db password]
POSTGRES_PASSWORD=[db user password]
$ cd django-on-docker
$ docker-compose -f docker-compose.development.yml up -d --build
...
Creating django-on-docker_db_1 ... done
Creating django-on-docker_app_1 ... done
Creating django-on-docker_nginx_1 ... done
$ docker-compose -f docker-compose.development.yml ps -a
Name Command State Ports
----------------------------------------------------------------------------------------
django-on-docker_app_1 /usr/src/app/entrypoint.de ... Up 8000/tcp
django-on-docker_db_1 docker-entrypoint.sh postgres Up 5432/tcp
django-on-docker_nginx_1 /docker-entrypoint.sh ngin ... Up 0.0.0.0:1337->80/tcp
All data deleted.
Remove data from all tables except for some, such as migration management.
$ docker-compose -f docker-compose.development.yml exec app python manage.py flush --no-input
Generating a migration files.
If a model modification occurs in subsequent development, it must be run again.
$ docker-compose -f docker-compose.development.yml exec app python manage.py makemigrations
Create DB tables from the generated migration files.
If a model modification occurs in subsequent development, it must be run again.
$ docker-compose -f docker-compose.development.yml exec app python manage.py migrate
Move the static files into the static directory.
$ docker-compose -f docker-compose.development.yml exec app python manage.py collectstatic --no-input --clear
Registering an administrative user.
$ docker-compose -f docker-compose.development.yml exec app python manage.py createsuperuser
Username (leave blank to use 'app'): [admin user name]
Email address: [admin user email]
Password: [admin user password]
Password (again):
Superuser created successfully.
page | url | note |
---|---|---|
Frontend file upload page | http://localhost:1337/uploads/ | Try file upload. |
Admin login | http://localhost:1337/admin/login/ | Enter the registered administrator's information. |
Stop the container and suspend development.
$ docker-compose -f docker-compose.development.yml stop
Start the container and resume development.
$ docker-compose -f docker-compose.development.yml start
Restart the container.
$ docker-compose -f docker-compose.development.yml restart
Destroy images, containers, volumes, and networks.
$ docker-compose -f docker-compose.development.yml down
If you want to modify only the app code and check the result, restart the app container only.
$ docker container restart django-on-docker_app_1
Recently Announced.
- Daisuke Sonoda
- mail@daisukesonoda.com
This repository is under MIT license.