File tree Expand file tree Collapse file tree 4 files changed +26
-0
lines changed Expand file tree Collapse file tree 4 files changed +26
-0
lines changed Original file line number Diff line number Diff line change @@ -1312,6 +1312,8 @@ docker-compose up
1312
1312
1313
1313

1314
1314
1315
+ :exclamation : 已經更新為自動 migrate:exclamation:
1316
+
1315
1317
但你仔細看上圖,你會發現他說你還沒 migrate
1316
1318
1317
1319
接下來我們開啟另一個 cmd 進入 web 的 service,
@@ -1334,6 +1336,12 @@ python manage.py migrate
1334
1336
1335
1337

1336
1338
1339
+ :exclamation : 已經更新為自動建立:exclamation:
1340
+
1341
+ 請參考 [docker-compose.yml](https://github.com/twtrubiks/docker-tutorial/blob/master/docker-compose.yml) 中的 environment ( 如下 ),
1342
+
1343
+ ` DJANGO_SUPERUSER_USERNAME` ` DJANGO_SUPERUSER_PASSWORD` ` DJANGO_SUPERUSER_EMAIL`
1344
+
1337
1345
順便在建立一個 superuser
1338
1346
1339
1347
` ` ` cmd
Original file line number Diff line number Diff line change @@ -6,3 +6,5 @@ WORKDIR /docker_api
6
6
COPY . /docker_api/
7
7
RUN pip install -r requirements.txt
8
8
9
+ # for entry point
10
+ RUN chmod +x /docker_api/docker-entrypoint.sh
Original file line number Diff line number Diff line change
1
+ #! /bin/sh
2
+ echo ' Run migration'
3
+ python3 manage.py makemigrations musics
4
+ python3 manage.py migrate
5
+ echo ' Create Super User'
6
+ python3 manage.py createsuperuser --noinput || echo " Super user already created"
7
+ exec " $@ "
Original file line number Diff line number Diff line change @@ -21,8 +21,17 @@ services:
21
21
22
22
web :
23
23
build : ./api
24
+ entrypoint : /docker_api/docker-entrypoint.sh
24
25
command : python manage.py runserver 0.0.0.0:8000
25
26
restart : always
27
+
28
+ # ref.
29
+ # https://docs.djangoproject.com/en/3.0/ref/django-admin/#django-admin-createsuperuser
30
+ environment :
31
+ - DJANGO_SUPERUSER_USERNAME=admin
32
+ - DJANGO_SUPERUSER_PASSWORD=admin1234
33
+ - DJANGO_SUPERUSER_EMAIL=admin@twtrubiks.com
34
+
26
35
volumes :
27
36
- api_data:/docker_api
28
37
# (HOST:CONTAINER)
You can’t perform that action at this time.
0 commit comments