File tree Expand file tree Collapse file tree 5 files changed +62
-26
lines changed Expand file tree Collapse file tree 5 files changed +62
-26
lines changed Original file line number Diff line number Diff line change 1+ SECRET_KEY = please_change_me
2+ SQL_ENGINE = django.db.backends.postgresql
3+ SQL_DATABASE = postgres
4+ SQL_USER = postgres
5+ SQL_PASSWORD = postgres
6+ SQL_HOST = db
7+ SQL_PORT = 5432
8+ DATABASE = postgres
Original file line number Diff line number Diff line change @@ -10,8 +10,20 @@ Check out the [post](https://testdriven.io/dockerizing-django-with-postgres-guni
1010
11111 . Build the images and run the containers:
1212
13+ - development (django default server):
14+
1315 ``` sh
1416 $ docker-compose up -d --build
1517 ```
18+ Test it out at [http://localhost:8000](http://localhost:8000)
19+
20+ App' s folder is mounted into container and your changes apply automatically.
21+
22+ - production (gunicorn + nginx):
23+
24+ ```sh
25+ $ docker-compose -f docker-compose.prod.yml up --build -d
26+ ```
27+ No mounted folders -- to apply changes container should be rebuilt
1628
17- 1. Test it out at [http://localhost:1337](http://localhost:1337)
29+ Test it out at [http://localhost:1337](http://localhost:1337)
Original file line number Diff line number Diff line change 11from django .contrib import admin
22from django .urls import path
3+ from django .conf import settings
4+ from django .conf .urls .static import static
35
46from upload .views import image_upload
57
68urlpatterns = [
79 path ('' , image_upload , name = 'upload' ),
810 path ('admin/' , admin .site .urls ),
911]
12+
13+ # to allow static in development mode. it could be removed when run via nginx
14+ urlpatterns += static (settings .MEDIA_URL , document_root = settings .MEDIA_ROOT )
Original file line number Diff line number Diff line change 1+ version : ' 3.7'
2+
3+ services :
4+ web :
5+ build : ./app
6+ command : gunicorn hello_django.wsgi:application --bind 0.0.0.0:8000
7+ volumes :
8+ - static_volume:/usr/src/app/staticfiles
9+ - media_volume:/usr/src/app/mediafiles
10+ expose :
11+ - 8000
12+ env_file : .env
13+ depends_on :
14+ - db
15+ db :
16+ image : postgres:10.5-alpine
17+ volumes :
18+ - postgres_data:/var/lib/postgresql/data/
19+ nginx :
20+ build : ./nginx
21+ volumes :
22+ - static_volume:/usr/src/app/staticfiles
23+ - media_volume:/usr/src/app/mediafiles
24+ ports :
25+ - 1337:80
26+ depends_on :
27+ - web
28+
29+ volumes :
30+ postgres_data :
31+ static_volume :
32+ media_volume :
Original file line number Diff line number Diff line change @@ -3,39 +3,18 @@ version: '3.7'
33services :
44 web :
55 build : ./app
6- command : gunicorn hello_django.wsgi:application --bind 0.0.0.0:8000
6+ command : python manage.py runserver 0.0.0.0:8000
77 volumes :
88 - ./app/:/usr/src/app/
9- - static_volume:/usr/src/app/staticfiles
10- - media_volume:/usr/src/app/mediafiles
11- expose :
12- - 8000
13- environment :
14- - SECRET_KEY=please_change_me
15- - SQL_ENGINE=django.db.backends.postgresql
16- - SQL_DATABASE=postgres
17- - SQL_USER=postgres
18- - SQL_PASSWORD=postgres
19- - SQL_HOST=db
20- - SQL_PORT=5432
21- - DATABASE=postgres
9+ ports :
10+ - " 8000:8000"
11+ env_file : .env
2212 depends_on :
2313 - db
2414 db :
2515 image : postgres:10.5-alpine
2616 volumes :
2717 - postgres_data:/var/lib/postgresql/data/
28- nginx :
29- build : ./nginx
30- volumes :
31- - static_volume:/usr/src/app/staticfiles
32- - media_volume:/usr/src/app/mediafiles
33- ports :
34- - 1337:80
35- depends_on :
36- - web
3718
3819volumes :
3920 postgres_data :
40- static_volume :
41- media_volume :
You can’t perform that action at this time.
0 commit comments