Ce diaporama a bien été signalé.
Nous utilisons votre profil LinkedIn et vos données d’activité pour vous proposer des publicités personnalisées et pertinentes. Vous pouvez changer vos préférences de publicités à tout moment.
raccoonyy
raccoonyy
raccoony @ Modern Server Lecture
ODK Media
https://44bits.io / https://stdout.fm
https://raccoonyy.git...
•
$ docker pull nginx
• git clone https://github.com/raccoonyy/
django-dockerizing
• cd django-dockerizing
• docker run --rm 

-v $(pwd)/django:...
.
├── Dockerfile
└── django
├── api
│   ├── apps.py
│   └── views.py
├── manage.py
├── requirements.txt
└── sample
├── set...
• pip install -r requirements.txt
• python manage.py collectstatic
• sample/settings.py
• DEBUG=False

DEBUG=os.environ.get('DEBUG', True)
• sample/settings.py
• ALLOWED_HOST = ('*', )

ALLOWED_HOST = (os.environ.get('HOST',
'*'), )
• sample/settings.py
• API_HOST = 'localhost:8000'

API_HOST = os.environ.get('API_HOST',
'localhost:8000')
• gunicorn sample.wsgi
• EMAIL_BACKEND
• SECRET_KEY
• ...
• pip install -r requirements.txt
• python manage.py collectstatic
• # sample/settings.py

DEBUG

ALLOWED_HOST

API_HOST
•...
FROM python:3.7.3
WORKDIR /usr/src/app

COPY django ./
RUN pip install -r requirements.txt

RUN python manage.py collectst...
• docker build -t docker-sample .
• docker run -it -p 8000:8000 docker-sample
• 13.125.183.70:8000/api/
• 13.125.183.70:80...
• Ctrl + C
$ docker ps

CONTAINER ID IMAGE ...

95bbb55fb111 docker-sample ...
$ docker kill 95bbb55fb111
$ docker rm 95bb...
$ docker run -d --rm -p 8000:8000 

docker-sample

...

$ open localhost:8000
• http://IP:8000/admin/
$ docker exec --rm docker-sample 

./manage.py migrate


$ docker exec -it --rm docker-sample 

./manage.py createsuperuse...
• http://IP:8000/admin/
Django
8000
HOST_IP
db.sqlite3
$ docker kill 95bbb55fb111
$ docker run -d --rm -p 8000:8000 

docker-sample

...

IP:8000
• http://IP:8000/admin/
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
}
}
: /us...
$ docker ps

CONTAINER ID IMAGE ...

ABCD1234EFGH docker-sample ...
$ docker kill ABCD1234EFGH
$ docker run -d --rm -p 800...
$ docker exec --rm docker-sample 

./manage.py migrate


$ docker exec -it --rm docker-sample 

./manage.py createsuperuse...
Django
db.sqlite3/usr/src/app/db.sqlite3
•
•
$ docker run -d --rm -p 8000:8000 

-v $(pwd)/django:/usr/src/app/ 

docker-sample
# bit.ly/msl-docker-compose-install
$ sudo curl -L "https://github.com/docker/
compose/release/download/1.24.0/docker-
com...
# ~/.bashrc 

alias dco='docker-compose'
# docker-compose.yml
version: '3'
services:
django:
image: docker-sample
ports:
- "8000:8000"
volumes:
- ./django:/usr/src...
•
•
•
•
•
# docker-compose.yml

services:

django:

image: docker-sample

ports:

- "8000:"8000"

volumes:

- ./django:/us...
$ docker-compose up -d (dco up -d)
...
$ docker-compose down (dco down)
...
•
•
$ docker run -p 60080:80 nginx
version: '3'
services:
nginx:
image: nginx
ports:
- 60080:80
•
•
•
version: '3'
services:
mysql:
image: mysql
error: database is uninitialized and
password option is not specified
You need to specify one of
MYSQL_ROOT_PASSWORD,
MYSQ...
version: '3'
services:
mysql:
image: mysql
environment:
- MYSQL_ROOT_PASSWORD:mypassword
version: '3'
services:
wordpress:
image: wordpress:latest
version: '3.3'
services:
db:
image: mysql:5.7
volumes:
- db_data:/var/lib/mysql
environment:
MYSQL_ROOT_PASSWORD: someword...
wordpress:
depends_on:
- db
image: wordpress:latest
ports:
- "60000:80"
restart: always
environment:
WORDPRESS_DB_HOST: db...
•
•
•
•
•
(docker-sample )
$ docker run -d --rm postgres
$ docker run -d --rm postgres

2603f8e32feecb5eb0cae...
$ docker logs -f 2603f
...
$ docker rm -f {CONTAINER_ID}
$ docker run -d --rm -p 5432:5432 postgres

$ docker rm -f {CONTAINER_ID}
$ docker run -d --rm -p 5432:5432 postgres

ad45e98618531ee693cc3...
$ docker logs ad45e

.....
$ docker rm -f {CONTAINER_ID}
$ docker run -d --rm -p 5432:5432 postgres

ad45e98618531ee693cc3...
$ telnet 0 5432

Trying...
$ docker run -d --rm 

-p 5432:5432 

-v $(pwd)/data:/var/lib/postgresql/data  

postgres
•
•
...
****************************************************
WARNING: No password has been set for the database.
This will all...
$ docker run -d 

-p 5432:5432 

-e POSTGRES_PASSWORD=rootpassword 

-v $(pwd)/data:/var/lib/postgresql/data  

postgres
•...
$ docker run -d 

-p 5432:5432 

-e POSTGRES_PASSWORD=rootpassword 

-v $(pwd)/data:/var/lib/postgresql/data  

postgres
•
$ docker run -d 

-p 5432:5432 

-e POSTGRES_PASSWORD=rootpassword 

-v $(pwd)/data:/var/lib/postgresql/data  

postgres
# ./docker-compose.yml
version: '3'



services:

db:

image: postgres

environment:

- POSTGRES_PASSWORD=rootpassword

vo...
• : docker-compose up -d
• : docker-compose ps
• : docker-compose logs
• : docker-compose down
• : docker-compose up -d
• -d
• : docker-compose ps
• : docker-compose logs -f
• -f
• : docker-compose down
•
• ./data
•
version: '3'



volumes:

postgres_data: {}



services:

db:

image: postgres

...

volumes:

- postgres_data:/var/lib/po...
postgres
/var/lib/postgres/data
postgres_data
•
• docker volume ls
• docker volume ls | grep postgres
• docker-compose
• docker-compose down -v
version: '3'

...

services:

db:

image: postgres

environment:

- POSTGRES_PASSWORD=rootpassword

- POSTGRES_USER=django...
•
db:

...

ports:

- 15432:5432

...
$ telnet 0 15432
Django
8000
HOST_IP
db.sqlite3
Django Postgres
5432
8000
HOST_IP
$ docker build -t docker-sample .
$ docker run -d --rm -p 8000:8000 docker-sample
# http://bit.ly/msl-django-database
# django/sample/settings.py
DATABASES = 

'default': {

'ENGINE': 'django.db.backends....
# django/requirements.txt
...
psycopg2-binary
# http://bit.ly/msl-postgres-docker
$ docker run -d 

--name db 

-p 5432:5432 

-e POSTGRES_DB=djangodb 

-e POSTGRES_USE...
$ docker run -d --rm 

-p 8000:8000 

--link db:db 

docker-sample
$ docker run -d --rm 

-p 8000:8000 

--link ABCD1234EF...
# Dockerfile
...
RUN apt update && apt install -y postgres-
client
RUN pip install ...
•
docker run -d --rm 

-p 8000:8000 

--link db:db 

-v $(pwd)/django:/usr/src/app 

docker-sample
•
• PYTHONUNBUFFERED
# Dockerfile

FROM python:3


ENV PYTHONUNBUFFERED 1

...
$ docker build -t docker-sample .
$ docker run -d --rm 

-p 8000:8000 

--link db:db 

-v $(pwd)/django:/usr/src/app 

doc...
$ docker run -d 

--name db 

-p 5432:5432 

-e POSTGRES_DB=djangodb 

-e POSTGRES_USER=django 

-e POSTGRES_PASSWORD=djan...
# docker-compose.yml
version: '3'



services:

db:

...

django:

image: docker-sample

links:

- db:db

ports:

- 8000:8...
Django Postgres
*
8000
HOST_IP
docker-compose

bridge network
•
•
•
•
# docker-compose.yml

...

django

# image: django-sample

build:

context: .

dockerfile: ./compose/django/
Dockerfile-de...
# ./compose/django/Dockerfile-dev
FROM python:3



ENV PYTHONUNBUFFERED 1



RUN apt update && apt install -y postgresql-c...
•
http://bit.ly/msl-django-postgres
version: '3'



services:

  django:

   build:

context: .

dockerfile: ./compose/django/Dockerfile-dev

links:

- db:db
...
...
db:

image: postgres

environment:

- POSTGRES_PASSWORD=rootpassword

- POSTGRES_USER=django

- POSTGRES_PASSWORD=djan...








•
•
•
•
•
•
•
•
•
•
•
•
http://bit.ly/msl-practice-guestbook
version: '3'



services:

 frontend:

   image: raccoony/guestbook-frontend:latest

   ports:

     - "60081:8080"

   en...
 backend:

   image: raccoony/guestbook-backend:latest

   environment:

     - PORT=5000

     - GUESTBOOK_DB_ADDR=mongod...
• exec
• run
• build
docker-compose run django ./manage.py
migrate
docker-compose run django bash
docker-compose exec django ./manage.py
check
docker-compose exec django bash
docker-compose build django
# ~/.bashrc 

alias dco='docker-compose'



alias dcb='docker-compose build'

alias dce='docker-compose exec'

alias dcps=...
raccoonyy@gmail.com
https://44bits.io
https://raccoonyy.github.io
raccoonyy
raccoonyy
Django로 만든 웹 애플리케이션 도커라이징하기 + 도커 컴포즈로 개발 환경 구축하기
Django로 만든 웹 애플리케이션 도커라이징하기 + 도커 컴포즈로 개발 환경 구축하기
Django로 만든 웹 애플리케이션 도커라이징하기 + 도커 컴포즈로 개발 환경 구축하기
Django로 만든 웹 애플리케이션 도커라이징하기 + 도커 컴포즈로 개발 환경 구축하기
Django로 만든 웹 애플리케이션 도커라이징하기 + 도커 컴포즈로 개발 환경 구축하기
Django로 만든 웹 애플리케이션 도커라이징하기 + 도커 컴포즈로 개발 환경 구축하기
Django로 만든 웹 애플리케이션 도커라이징하기 + 도커 컴포즈로 개발 환경 구축하기
Django로 만든 웹 애플리케이션 도커라이징하기 + 도커 컴포즈로 개발 환경 구축하기
Django로 만든 웹 애플리케이션 도커라이징하기 + 도커 컴포즈로 개발 환경 구축하기
Django로 만든 웹 애플리케이션 도커라이징하기 + 도커 컴포즈로 개발 환경 구축하기
Django로 만든 웹 애플리케이션 도커라이징하기 + 도커 컴포즈로 개발 환경 구축하기
Django로 만든 웹 애플리케이션 도커라이징하기 + 도커 컴포즈로 개발 환경 구축하기
Django로 만든 웹 애플리케이션 도커라이징하기 + 도커 컴포즈로 개발 환경 구축하기
Django로 만든 웹 애플리케이션 도커라이징하기 + 도커 컴포즈로 개발 환경 구축하기
Django로 만든 웹 애플리케이션 도커라이징하기 + 도커 컴포즈로 개발 환경 구축하기
Django로 만든 웹 애플리케이션 도커라이징하기 + 도커 컴포즈로 개발 환경 구축하기
Django로 만든 웹 애플리케이션 도커라이징하기 + 도커 컴포즈로 개발 환경 구축하기
Django로 만든 웹 애플리케이션 도커라이징하기 + 도커 컴포즈로 개발 환경 구축하기
Django로 만든 웹 애플리케이션 도커라이징하기 + 도커 컴포즈로 개발 환경 구축하기
Django로 만든 웹 애플리케이션 도커라이징하기 + 도커 컴포즈로 개발 환경 구축하기
Django로 만든 웹 애플리케이션 도커라이징하기 + 도커 컴포즈로 개발 환경 구축하기
Django로 만든 웹 애플리케이션 도커라이징하기 + 도커 컴포즈로 개발 환경 구축하기
Django로 만든 웹 애플리케이션 도커라이징하기 + 도커 컴포즈로 개발 환경 구축하기
Django로 만든 웹 애플리케이션 도커라이징하기 + 도커 컴포즈로 개발 환경 구축하기
Prochain SlideShare
Chargement dans…5
×

Django로 만든 웹 애플리케이션 도커라이징하기 + 도커 컴포즈로 개발 환경 구축하기

파이콘 2019 튜토리얼에서 진행한 발표 내용입니다

  • Soyez le premier à commenter

Django로 만든 웹 애플리케이션 도커라이징하기 + 도커 컴포즈로 개발 환경 구축하기

  1. 1. raccoonyy raccoonyy raccoony @ Modern Server Lecture ODK Media https://44bits.io / https://stdout.fm https://raccoonyy.github.io
  2. 2. • $ docker pull nginx
  3. 3. • git clone https://github.com/raccoonyy/ django-dockerizing • cd django-dockerizing • docker run --rm 
 -v $(pwd)/django:/usr/src/app 
 python:3 bash • cd /usr/src/app • (Windows $(pwd) %cd%)
  4. 4. . ├── Dockerfile └── django ├── api │   ├── apps.py │   └── views.py ├── manage.py ├── requirements.txt └── sample ├── settings.py ├── urls.py └── wsgi.py
  5. 5. • pip install -r requirements.txt • python manage.py collectstatic
  6. 6. • sample/settings.py • DEBUG=False
 DEBUG=os.environ.get('DEBUG', True)
  7. 7. • sample/settings.py • ALLOWED_HOST = ('*', )
 ALLOWED_HOST = (os.environ.get('HOST', '*'), )
  8. 8. • sample/settings.py • API_HOST = 'localhost:8000'
 API_HOST = os.environ.get('API_HOST', 'localhost:8000')
  9. 9. • gunicorn sample.wsgi
  10. 10. • EMAIL_BACKEND • SECRET_KEY • ...
  11. 11. • pip install -r requirements.txt • python manage.py collectstatic • # sample/settings.py
 DEBUG
 ALLOWED_HOST
 API_HOST • gunicorn sample.wsgi
  12. 12. FROM python:3.7.3 WORKDIR /usr/src/app
 COPY django ./ RUN pip install -r requirements.txt
 RUN python manage.py collectstatic --noinput CMD ["gunicorn", "sample.wsgi", "--bind=0:8000"]
  13. 13. • docker build -t docker-sample . • docker run -it -p 8000:8000 docker-sample • 13.125.183.70:8000/api/ • 13.125.183.70:8000/api/ database/ • 13.125.183.70:8000/api/message/
  14. 14. • Ctrl + C $ docker ps
 CONTAINER ID IMAGE ...
 95bbb55fb111 docker-sample ... $ docker kill 95bbb55fb111 $ docker rm 95bbb55fb111
  15. 15. $ docker run -d --rm -p 8000:8000 
 docker-sample
 ...
 $ open localhost:8000
  16. 16. • http://IP:8000/admin/
  17. 17. $ docker exec --rm docker-sample 
 ./manage.py migrate 
 $ docker exec -it --rm docker-sample 
 ./manage.py createsuperuser Username (leave blank to use 'root'):
  18. 18. • http://IP:8000/admin/
  19. 19. Django 8000 HOST_IP db.sqlite3
  20. 20. $ docker kill 95bbb55fb111 $ docker run -d --rm -p 8000:8000 
 docker-sample
 ...
 IP:8000
  21. 21. • http://IP:8000/admin/
  22. 22. DATABASES = { 'default': { 'ENGINE': 'django.db.backends.sqlite3', 'NAME': os.path.join(BASE_DIR, 'db.sqlite3'), } } : /usr/src/app/db.sqlite3
  23. 23. $ docker ps
 CONTAINER ID IMAGE ...
 ABCD1234EFGH docker-sample ... $ docker kill ABCD1234EFGH $ docker run -d --rm -p 8000:8000 
 -v $(pwd)/django:/usr/src/app/ 
 docker-sample
  24. 24. $ docker exec --rm docker-sample 
 ./manage.py migrate 
 $ docker exec -it --rm docker-sample 
 ./manage.py createsuperuser Username (leave blank to use 'root'):
  25. 25. Django db.sqlite3/usr/src/app/db.sqlite3
  26. 26. • •
  27. 27. $ docker run -d --rm -p 8000:8000 
 -v $(pwd)/django:/usr/src/app/ 
 docker-sample
  28. 28. # bit.ly/msl-docker-compose-install $ sudo curl -L "https://github.com/docker/ compose/release/download/1.24.0/docker- compose-$(uname -s)-$(uname -m)" -o /usr/ local/bin/docker-compose
  29. 29. # ~/.bashrc 
 alias dco='docker-compose'
  30. 30. # docker-compose.yml version: '3' services: django: image: docker-sample ports: - "8000:8000" volumes: - ./django:/usr/src/app $ docker run -d --rm 
 -p 8000:8000 
 -v $(pwd)/django:/usr/src/app/ 
 docker-sample
  31. 31. • • • • • # docker-compose.yml
 services:
 django:
 image: docker-sample
 ports:
 - "8000:"8000"
 volumes:
 - ./django:/usr/src/app
  32. 32. $ docker-compose up -d (dco up -d) ...
  33. 33. $ docker-compose down (dco down) ...
  34. 34. • •
  35. 35. $ docker run -p 60080:80 nginx
  36. 36. version: '3' services: nginx: image: nginx ports: - 60080:80
  37. 37. • • •
  38. 38. version: '3' services: mysql: image: mysql
  39. 39. error: database is uninitialized and password option is not specified You need to specify one of MYSQL_ROOT_PASSWORD, MYSQL_ALLOW_EMPTY_PASSWORD and MYSQL_RANDOM_ROOT_PASSWORD
  40. 40. version: '3' services: mysql: image: mysql environment: - MYSQL_ROOT_PASSWORD:mypassword
  41. 41. version: '3' services: wordpress: image: wordpress:latest
  42. 42. version: '3.3' services: db: image: mysql:5.7 volumes: - db_data:/var/lib/mysql environment: MYSQL_ROOT_PASSWORD: somewordpress MYSQL_DATABASE: wordpress MYSQL_USER: wordpress MYSQL_PASSWORD: wordpress
  43. 43. wordpress: depends_on: - db image: wordpress:latest ports: - "60000:80" restart: always environment: WORDPRESS_DB_HOST: db:3306 WORDPRESS_DB_USER: wordpress WORDPRESS_DB_PASSWORD: wordpress WORDPRESS_DB_NAME: wordpress volumes: db_data: {}
  44. 44. • • • • •
  45. 45. (docker-sample ) $ docker run -d --rm postgres
  46. 46. $ docker run -d --rm postgres
 2603f8e32feecb5eb0cae... $ docker logs -f 2603f ...
  47. 47. $ docker rm -f {CONTAINER_ID} $ docker run -d --rm -p 5432:5432 postgres

  48. 48. $ docker rm -f {CONTAINER_ID} $ docker run -d --rm -p 5432:5432 postgres
 ad45e98618531ee693cc3... $ docker logs ad45e
 ... PostgreSQL init process complete; ready for start up. ... listening on IPv4 address "0.0.0.0", port 5432
  49. 49. $ docker rm -f {CONTAINER_ID} $ docker run -d --rm -p 5432:5432 postgres
 ad45e98618531ee693cc3... $ telnet 0 5432
 Trying 0.0.0.0...
 Connected to 0.
 Escape character is '^]'. telnet> quit
  50. 50. $ docker run -d --rm 
 -p 5432:5432 
 -v $(pwd)/data:/var/lib/postgresql/data 
 postgres • •
  51. 51. ... **************************************************** WARNING: No password has been set for the database. This will allow anyone with access to the Postgres port to access your database. In Docker's default configuration, this is effectively any other container on the same system. Use "-e POSTGRES_PASSWORD=password" to set it in "docker run". **************************************************** ...
  52. 52. $ docker run -d 
 -p 5432:5432 
 -e POSTGRES_PASSWORD=rootpassword 
 -v $(pwd)/data:/var/lib/postgresql/data 
 postgres • https://hub.docker.com/_/ postgres
  53. 53. $ docker run -d 
 -p 5432:5432 
 -e POSTGRES_PASSWORD=rootpassword 
 -v $(pwd)/data:/var/lib/postgresql/data 
 postgres
  54. 54. • $ docker run -d 
 -p 5432:5432 
 -e POSTGRES_PASSWORD=rootpassword 
 -v $(pwd)/data:/var/lib/postgresql/data 
 postgres
  55. 55. # ./docker-compose.yml version: '3'
 
 services:
 db:
 image: postgres
 environment:
 - POSTGRES_PASSWORD=rootpassword
 volumes:
 - ./data:/var/lib/postgres/data
 ports:
 - 5432:5432
  56. 56. • : docker-compose up -d • : docker-compose ps • : docker-compose logs • : docker-compose down
  57. 57. • : docker-compose up -d • -d • : docker-compose ps • : docker-compose logs -f • -f • : docker-compose down
  58. 58. • • ./data
  59. 59.
  60. 60. version: '3'
 
 volumes:
 postgres_data: {}
 
 services:
 db:
 image: postgres
 ...
 volumes:
 - postgres_data:/var/lib/postgres/data
  61. 61. postgres /var/lib/postgres/data postgres_data
  62. 62. • • docker volume ls • docker volume ls | grep postgres • docker-compose • docker-compose down -v
  63. 63. version: '3'
 ...
 services:
 db:
 image: postgres
 environment:
 - POSTGRES_PASSWORD=rootpassword
 - POSTGRES_USER=django
 - POSTGRES_PASSWORD=django_password
 - POSTGRES_DB=djangodb
 volumes:
 ...
  64. 64.
  65. 65. db:
 ...
 ports:
 - 15432:5432
 ... $ telnet 0 15432
  66. 66. Django 8000 HOST_IP db.sqlite3
  67. 67. Django Postgres 5432 8000 HOST_IP
  68. 68. $ docker build -t docker-sample . $ docker run -d --rm -p 8000:8000 docker-sample
  69. 69. # http://bit.ly/msl-django-database # django/sample/settings.py DATABASES = 
 'default': {
 'ENGINE': 'django.db.backends.postgresql',
 'NAME': os.environ.get('DJANGO_DB_NAME', 
 'djangodb'),
 'USER': os.environ.get('DJANGO_DB_USERNAME', 
 'django'),
 'PASSWORD': os.environ.get('DJANGO_DB_PASSWORD', 
 'django_password'),
 'HOST': os.environ.get('DJANGO_DB_HOST', 'db'),
 'PORT': os.environ.get('DJANGO_DB_PORT', '5432'),
 }
 }
  70. 70. # django/requirements.txt ... psycopg2-binary
  71. 71. # http://bit.ly/msl-postgres-docker $ docker run -d 
 --name db 
 -p 5432:5432 
 -e POSTGRES_DB=djangodb 
 -e POSTGRES_USER=django 
 -e POSTGRES_PASSWORD=djangopassword 
 -v $(pwd)/data:/var/lib/postgresql/data 
 postgres
  72. 72. $ docker run -d --rm 
 -p 8000:8000 
 --link db:db 
 docker-sample $ docker run -d --rm 
 -p 8000:8000 
 --link ABCD1234EFGH:db 
 docker-sample
  73. 73. # Dockerfile ... RUN apt update && apt install -y postgres- client RUN pip install ...
  74. 74.
  75. 75. docker run -d --rm 
 -p 8000:8000 
 --link db:db 
 -v $(pwd)/django:/usr/src/app 
 docker-sample
  76. 76. • • PYTHONUNBUFFERED
  77. 77. # Dockerfile
 FROM python:3 
 ENV PYTHONUNBUFFERED 1
 ...
  78. 78. $ docker build -t docker-sample . $ docker run -d --rm 
 -p 8000:8000 
 --link db:db 
 -v $(pwd)/django:/usr/src/app 
 docker-sample
  79. 79. $ docker run -d 
 --name db 
 -p 5432:5432 
 -e POSTGRES_DB=djangodb 
 -e POSTGRES_USER=django 
 -e POSTGRES_PASSWORD=djangopassword 
 -v $(pwd)/data:/var/lib/postgresql/data 
 postgres
 
 $ docker run -d --rm 
 -p 8000:8000 
 --link db:db 
 -v $(pwd)/django:/usr/src/app 
 docker-sample
  80. 80. # docker-compose.yml version: '3'
 
 services:
 db:
 ...
 django:
 image: docker-sample
 links:
 - db:db
 ports:
 - 8000:8000
 volumes:
 - ./django:/usr/src/app
  81. 81. Django Postgres * 8000 HOST_IP docker-compose
 bridge network
  82. 82. • • • •
  83. 83. # docker-compose.yml
 ...
 django
 # image: django-sample
 build:
 context: .
 dockerfile: ./compose/django/ Dockerfile-dev
 ...
  84. 84. # ./compose/django/Dockerfile-dev FROM python:3
 
 ENV PYTHONUNBUFFERED 1
 
 RUN apt update && apt install -y postgresql-client
 
 WORKDIR /usr/src/app
 COPY django ./
 COPY django/requirements.txt ./
 RUN pip install -r requirements.txt
 RUN python manage.py collectstatic --noinput
 
 CMD ["gunicorn", "sample.wsgi", "--bind=0:8000"]
  85. 85.
  86. 86. http://bit.ly/msl-django-postgres
  87. 87. version: '3'
 
 services:
   django:
    build:
 context: .
 dockerfile: ./compose/django/Dockerfile-dev
 links:
 - db:db
 ports:
 - 8000:8000
 volumes:
 - ./django:/usr/src/app
 restart: always
  88. 88. ... db:
 image: postgres
 environment:
 - POSTGRES_PASSWORD=rootpassword
 - POSTGRES_USER=django
 - POSTGRES_PASSWORD=django_password
 - POSTGRES_DB=djangodb
 volumes:
 - postgres_data:/var/lib/postgres/data
 
 volumes:
 postgres_data: {}
  89. 89. 
 
 
 

  90. 90. • • • • • • • • • • • •
  91. 91. http://bit.ly/msl-practice-guestbook
  92. 92. version: '3'
 
 services:
  frontend:
    image: raccoony/guestbook-frontend:latest
    ports:
      - "60081:8080"
    environment:
      - PORT=8080
      - GUESTBOOK_API_ADDR=backend:5000
    depends_on:
      - backend
 
  backend:
    image: raccoony/guestbook-backend:latest
    environment:
      - PORT=5000
      - GUESTBOOK_DB_ADDR=mongodb:27017
    depends_on:
      - mongodb
  93. 93.  backend:
    image: raccoony/guestbook-backend:latest
    environment:
      - PORT=5000
      - GUESTBOOK_DB_ADDR=mongodb:27017
    depends_on:
      - mongodb
 
  mongodb:
    image: mongo:4
    volumes:
      - mongo_data:/data/db
 
 volumes:
  mongo_data:{}
  94. 94. • exec • run • build
  95. 95. docker-compose run django ./manage.py migrate docker-compose run django bash
  96. 96. docker-compose exec django ./manage.py check docker-compose exec django bash
  97. 97. docker-compose build django
  98. 98. # ~/.bashrc 
 alias dco='docker-compose'
 
 alias dcb='docker-compose build'
 alias dce='docker-compose exec'
 alias dcps='docker-compose ps'
 alias dcr='docker-compose run'
 alias dcup='docker-compose up'
 alias dcdn='docker-compose down'
 alias dcl='docker-compose logs'
 alias dclf='docker-compose logs -f'
  99. 99. raccoonyy@gmail.com https://44bits.io https://raccoonyy.github.io raccoonyy raccoonyy

×