SlideShare a Scribd company logo
1
2
3
4
easy_install pip setup.py install
5
6
$ pip install -r requirements.txt
7
8
$ pip install -r requirements.txt
...
build/temp.macosx-10.11-x86_64-3.5/_openssl.c:400:10:
fatal error: 'openssl/aes.h' file not found
#include <openssl/aes.h>
^
1 error generated.
error: command 'clang' failed with exit status 1
9
...
ld: library not found for -lpq
collect2: ld returned 1 exit status
ld: library not found for -lpq
collect2: ld returned 1 exit status
error: command 'clang' failed with exit status 1
10
...
building '_imaging' extension
creating build/temp.macosx-10.8-intel-2.7
creating build/temp.macosx-10.8-intel-2.7/libImaging
...
unable to execute clang: No such file or directory
error: command 'clang' failed with exit status 1
11
...
Skipping installation of /Library/Python/2.7/site-packages/
virtualenvwrapper/init.py (namespace package)
copying virtualenvwrapper/hook_loader.py -> /Library/Python/
2.7/site-packages/virtualenvwrapper
error: /Library/Python/2.7/site-packages/virtualenvwrapper:
Permission denied
12
export XXXXXXX=-xxxxxx
13
$ sudo pip install xxx
14
$ brew install xxx
15
ImportError: No module named xxx
16
apt install xxx
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
$ docker run -it python:3.7.0b4-stretch
Unable to find image 'python:3.7.0b4-stretch' locally
3.7.0b4-stretch: Pulling from library/python
cc1a78bfd46b: Extracting 16.52MB/45.32MB
6861473222a6: Download complete
7e0b9c3b5ae0: Download complete
3ec98735f56f: Downloading 14.75MB/50.03MB
9b311b87a021: Downloading 57.12MB/213.2MB
048165938570: Download complete
b98bafe8d054: Pulling fs layer
9e173e93364f: Pulling fs layer
279629a74d4e: Waiting
35
$ docker run -it python:3.7.0b4-stretch
Unable to find image 'python:3.7.0b4-stretch' locally
3.7.0b4-stretch: Pulling from library/python
cc1a78bfd46b: Pull complete
6861473222a6: Pull complete
7e0b9c3b5ae0: Pull complete
3ec98735f56f: Pull complete
9b311b87a021: Pull complete
048165938570: Pull complete
b98bafe8d054: Pull complete
9e173e93364f: Pull complete
279629a74d4e: Pull complete
Digest: sha256:4b4314d7020b5b2730ddc1fbe5be3a6f2f6cd2478156bc652a37bec012ff89dd
Status: Downloaded newer image for python:3.7.0b4-stretch
Python 3.7.0b4 (default, May 5 2018, 02:57:38)
[GCC 6.3.0 20170516] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>>
36
37
38
39
$ docker run -it python:3
Python 3.6.5 (default, May 5 2018, 03:09:35)
[GCC 4.9.2] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> 1 + 1
2
>>>
40
$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
4fb53528e038 python:3 "python3" 2 seconds ago Up 1 second flamboyant_lichterman
$ docker logs 4fb53528e038
Python 3.6.5 (default, May 5 2018, 03:09:35)
[GCC 4.9.2] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> 1 + 1
2
$
41
$ docker exec -it 4fb53528e038 bash
root@4fb53528e038:/# ls
bin dev home lib64 mnt proc run srv tmp var
boot etc lib media opt root sbin sys usr
root@4fb53528e038:/#
42
$ docker run -it python:3
$ docker logs 4fb53528e038
python:3
4fb53528e038
43
$ docker run -it python:3
Python 3.6.5 (default, May 5 2018, 03:09:35)
[GCC 4.9.2] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> exit()
$ docker run -it python:3 bash
root@b1ae1f2de579:/#
44
$ docker run -it --env CONF_NAME=pycon_seminar python:3 bash
root@04cc7afe7362:/# echo $CONF_NAME
pycon_seminar
root@04cc7afe7362:/#
45
$ ls djangosample
__init__.py settings.py urls.py wsgi.py
$ docker run -it --volume `pwd`/djangosample:/djangosample python:3 bash
root@04cc7afe7362:/# ls /djangosample
__init__.py settings.py urls.py wsgi.py
root@04cc7afe7362:/#
46
47
48
python:3
--volume
bash
--env
49
50
51
FROM python:3
RUN apt-get update && apt-get -y install 
libpq-dev
ADD ./djangosample /app/
WORKDIR /app
CMD ["python", "manage.py", "runserver", "0:8000"]
52
$ git clone https://github.com/raccoonyy/django-sample-for-docker-compose
$ cd django-sample-for-docker-compose
$ docker build -t my-django .
53
$ docker run -d 
--env POSTGRES_DB=djangosample 
--env POSTGRES_USER=sampleuser 
--env POSTGRES_PASSWORD=samplesecret 
--name db 
postgres
$ docker run -it 
--env DJANGO_DEBUG=True 
--env DJANGO_DB_HOST=postgres 
--link db:postgres 
--publish 8000:8000 
my-django
$ open http://127.0.0.1:8000
54
--name db db
--link db:postgres db postgres
--publish 8000:8000
55
$ mkdir data
$ docker run -d 
--env POSTGRES_DB=djangosample 
--env POSTGRES_USER=sampleuser 
--env POSTGRES_PASSWORD=samplesecret 
--name db 
--volume data:/var/lib/postgresql/data  <-- New!
postgres
56
$ docker run -d 
--env POSTGRES_DB=djangosample 
--env POSTGRES_USER=sampleuser 
--env POSTGRES_PASSWORD=samplesecret 
--name db 
--volume `pwd`/data:/var/lib/postgresql/data 
--rm <-- New!
postgres
57
$ docker run -it 
--env DJANGO_DEBUG=True 
--env DJANGO_DB_HOST=postgres 
--link my-postgres:postgres 
--publish 8000:8000 
--volume `pwd`:/app  <-- New!
my-django
58
59
$ docker-compose up
60
version: '3'
volumes:
django_sample_db_dev: {}
services:
db:
image: postgres
volumes:
- django_sample_db_dev:/var/lib/postgresql/data
environment:
- POSTGRES_DB=sampledb
- POSTGRES_USER=sampleuser
- POSTGRES_PASSWORD=samplesecret
django:
build:
context: .
dockerfile: ./compose/django/Dockerfile-dev
environment:
- DJANGO_DEBUG=True
- DJANGO_DB_HOST=postgres
- DJANGO_DB_PORT=5432
- DJANGO_DB_NAME=sampledb
- DJANGO_DB_USERNAME=sampleuser
- DJANGO_DB_PASSWORD=samplesecret
- DJANGO_SECRET_KEY=dev_secret_key
ports:
- "8000:8000"
depends_on:
- db
links:
- db:postgres
command: ["/wait-for-it.sh", "postgres:5432", "-t", "10", "--", "/start-dev.sh"]
volumes:
- ./djangosample:/app/djangosample
61
version: '3'
volumes:
django_sample_db_dev: {}
services:
db:
image: postgres
volumes:
- django_sample_db_dev:/var/lib/postgresql/data
environment:
- POSTGRES_DB=sampledb
- POSTGRES_USER=sampleuser
- POSTGRES_PASSWORD=samplesecret
62
django:
build:
context: .
dockerfile: ./compose/django/Dockerfile-dev
environment:
- DJANGO_DEBUG=True
- DJANGO_DB_HOST=postgres
- DJANGO_DB_PORT=5432
- DJANGO_DB_NAME=sampledb
- DJANGO_DB_USERNAME=sampleuser
- DJANGO_DB_PASSWORD=samplesecret
- DJANGO_SECRET_KEY=dev_secret_key
ports:
- "8000:8000"
depends_on:
- db
links:
- db:postgres
volumes:
- ./:/app/
63
python:3 image build
--volume volumes
--env environment
--link links
depends_on
--publish ports
64
65
$ docker-compose ps
Name Command State Ports
---------------------------------------------------------------------------------------------------------
django-sample-for-docker-compose_db_1 docker-entrypoint.sh postgres Up 5432/tcp
django-sample-for-docker- bash -c python manage.py m ... Up 0.0.0.0:8000->8000/tcp
compose_django_1
66
$ docker-compose up
$ docker-compose up -d
67
$ docker-compose logs [service name]
$ docker-compose logs -f [service name]
68
$ docker-compose exec django bash
root@3707e50b0c9a:/app#
69
$ docker-compose down
Stopping django-sample-for-docker-compose_django_1 ... done
Stopping django-sample-for-docker-compose_db_1 ... done
Removing django-sample-for-docker-compose_django_1 ... done
Removing django-sample-for-docker-compose_db_1 ... done
Removing network django-sample-for-docker-compose_default
$ docker-compose down -v
70
71
# docker-compose.yml
django:
...
stdin_open: true
tty: true
$ docker attach CONTAINER_ID
72
bash command
# docker-compose.yml
service:
...
django:
...
command:
- bash
- -c
- |
python manage.py migrate
python manage.py runserver 0:8000
73
# Dockerfile
ENV PYTHONUNBUFFERED 0
74
$ docker-compose up --build
$ docker-compose up --force-recreate
75
76
77
78
79
80

More Related Content

What's hot (20)

PDF
Running Django on Docker: a workflow and code
Danielle Madeley
 
PPTX
Docker on openstack by OpenSource Consulting
Open Source Consulting
 
PDF
Introducing Docker
Francesco Pantano
 
PPTX
Docker orchestration
Open Source Consulting
 
PDF
이미지 기반의 배포 패러다임 Immutable infrastructure
Daegwon Kim
 
PDF
A Hands-on Introduction to Docker
CodeOps Technologies LLP
 
PPTX
Running Docker in Development & Production (#ndcoslo 2015)
Ben Hall
 
PPTX
Docker toolbox
Yonghwee Kim
 
PDF
Docker up and running
Victor S. Recio
 
PDF
Docker 활용법: dumpdocker
Jaehwa Park
 
PDF
手把手帶你學Docker 03042017
Paul Chao
 
PPTX
Deploying Windows Containers on Windows Server 2016
Ben Hall
 
PPTX
Deploying Symfony2 app with Ansible
Roman Rodomansky
 
PDF
Scaling Next-Generation Internet TV on AWS With Docker, Packer, and Chef
bridgetkromhout
 
PPTX
Real World Experience of Running Docker in Development and Production
Ben Hall
 
PDF
The state of the swarm
Mathieu Buffenoir
 
PDF
Docker puebla bday #4 celebration
Ramon Morales
 
PDF
2017-03-11 02 Денис Нелюбин. Docker & Ansible - лучшие друзья DevOps
Омские ИТ-субботники
 
PPTX
Running Docker in Development & Production (DevSum 2015)
Ben Hall
 
PPTX
Dockerizing a Symfony2 application
Roman Rodomansky
 
Running Django on Docker: a workflow and code
Danielle Madeley
 
Docker on openstack by OpenSource Consulting
Open Source Consulting
 
Introducing Docker
Francesco Pantano
 
Docker orchestration
Open Source Consulting
 
이미지 기반의 배포 패러다임 Immutable infrastructure
Daegwon Kim
 
A Hands-on Introduction to Docker
CodeOps Technologies LLP
 
Running Docker in Development & Production (#ndcoslo 2015)
Ben Hall
 
Docker toolbox
Yonghwee Kim
 
Docker up and running
Victor S. Recio
 
Docker 활용법: dumpdocker
Jaehwa Park
 
手把手帶你學Docker 03042017
Paul Chao
 
Deploying Windows Containers on Windows Server 2016
Ben Hall
 
Deploying Symfony2 app with Ansible
Roman Rodomansky
 
Scaling Next-Generation Internet TV on AWS With Docker, Packer, and Chef
bridgetkromhout
 
Real World Experience of Running Docker in Development and Production
Ben Hall
 
The state of the swarm
Mathieu Buffenoir
 
Docker puebla bday #4 celebration
Ramon Morales
 
2017-03-11 02 Денис Нелюбин. Docker & Ansible - лучшие друзья DevOps
Омские ИТ-субботники
 
Running Docker in Development & Production (DevSum 2015)
Ben Hall
 
Dockerizing a Symfony2 application
Roman Rodomansky
 

Similar to 파이썬 개발환경 구성하기의 끝판왕 - Docker Compose (20)

PDF
Using docker for data science - part 2
Calvin Giles
 
PPTX
2012 coscup - Build your PHP application on Heroku
ronnywang_tw
 
PDF
Troubleshooting Tips from a Docker Support Engineer - Jeff Anderson, Docker
Docker, Inc.
 
PDF
Troubleshooting Tips from a Docker Support Engineer
Jeff Anderson
 
PDF
DCEU 18: Tips and Tricks of the Docker Captains
Docker, Inc.
 
PDF
Challenges of container configuration
lutter
 
PDF
PuppetConf 2016: The Challenges with Container Configuration – David Lutterko...
Puppet
 
PDF
PFIセミナー資料 H27.10.22
Yuya Takei
 
KEY
Railsconf2011 deployment tips_for_slideshare
tomcopeland
 
PPT
Why and How Powershell will rule the Command Line - Barcamp LA 4
Ilya Haykinson
 
PPTX
Docker practice
wonyong hwang
 
PDF
Docker perl build
Workhorse Computing
 
PPTX
Azure from scratch part 5 By Girish Kalamati
Girish Kalamati
 
PPTX
Docker Security workshop slides
Docker, Inc.
 
PDF
Docker 初探,實驗室中的運貨鯨
Ruoshi Ling
 
PDF
Docker, c'est bonheur !
Alexandre Salomé
 
PDF
Keep it simple web development stack
Eric Ahn
 
DOC
X64服务器 lnmp服务器部署标准 new
Yiwei Ma
 
PDF
Beyond Golden Containers: Complementing Docker with Puppet
lutter
 
PDF
Docker by Example - Basics
CodeOps Technologies LLP
 
Using docker for data science - part 2
Calvin Giles
 
2012 coscup - Build your PHP application on Heroku
ronnywang_tw
 
Troubleshooting Tips from a Docker Support Engineer - Jeff Anderson, Docker
Docker, Inc.
 
Troubleshooting Tips from a Docker Support Engineer
Jeff Anderson
 
DCEU 18: Tips and Tricks of the Docker Captains
Docker, Inc.
 
Challenges of container configuration
lutter
 
PuppetConf 2016: The Challenges with Container Configuration – David Lutterko...
Puppet
 
PFIセミナー資料 H27.10.22
Yuya Takei
 
Railsconf2011 deployment tips_for_slideshare
tomcopeland
 
Why and How Powershell will rule the Command Line - Barcamp LA 4
Ilya Haykinson
 
Docker practice
wonyong hwang
 
Docker perl build
Workhorse Computing
 
Azure from scratch part 5 By Girish Kalamati
Girish Kalamati
 
Docker Security workshop slides
Docker, Inc.
 
Docker 初探,實驗室中的運貨鯨
Ruoshi Ling
 
Docker, c'est bonheur !
Alexandre Salomé
 
Keep it simple web development stack
Eric Ahn
 
X64服务器 lnmp服务器部署标准 new
Yiwei Ma
 
Beyond Golden Containers: Complementing Docker with Puppet
lutter
 
Docker by Example - Basics
CodeOps Technologies LLP
 
Ad

More from raccoony (12)

PDF
How to survive in AWS re:Invent
raccoony
 
PDF
select-fix(일괄 바꿈) 프로젝트 소개
raccoony
 
PDF
Write The Docs 서울의 2019년 첫 밋업 소개 자료
raccoony
 
PDF
번역 작업의 지속 가능성을 높이는 CAT
raccoony
 
PDF
한글 폰트 크기 문제를 테스트해봅니다
raccoony
 
PDF
Docker (Compose) 활용 - 개발 환경 구성하기
raccoony
 
PDF
음향 기초 안내서
raccoony
 
PDF
인디자인을 활용한 자동 조판 실험
raccoony
 
PDF
민주주의를 위한 대화, 소통, 참여, 협력의 기술
raccoony
 
PDF
(중학생도 이해하는) 에니그마의 작동 원리
raccoony
 
PDF
서버 개발자가 되기 전에 알았으면 좋았을 것들
raccoony
 
PDF
Sublime Text 3 for python and django
raccoony
 
How to survive in AWS re:Invent
raccoony
 
select-fix(일괄 바꿈) 프로젝트 소개
raccoony
 
Write The Docs 서울의 2019년 첫 밋업 소개 자료
raccoony
 
번역 작업의 지속 가능성을 높이는 CAT
raccoony
 
한글 폰트 크기 문제를 테스트해봅니다
raccoony
 
Docker (Compose) 활용 - 개발 환경 구성하기
raccoony
 
음향 기초 안내서
raccoony
 
인디자인을 활용한 자동 조판 실험
raccoony
 
민주주의를 위한 대화, 소통, 참여, 협력의 기술
raccoony
 
(중학생도 이해하는) 에니그마의 작동 원리
raccoony
 
서버 개발자가 되기 전에 알았으면 좋았을 것들
raccoony
 
Sublime Text 3 for python and django
raccoony
 
Ad

Recently uploaded (20)

PPTX
Lecture 5 - Agentic AI and model context protocol.pptx
Dr. LAM Yat-fai (林日辉)
 
PPTX
Simplifying End-to-End Apache CloudStack Deployment with a Web-Based Automati...
ShapeBlue
 
PPTX
Building and Operating a Private Cloud with CloudStack and LINBIT CloudStack ...
ShapeBlue
 
PDF
Women in Automation Presents: Reinventing Yourself — Bold Career Pivots That ...
DianaGray10
 
PDF
Meetup Kickoff & Welcome - Rohit Yadav, CSIUG Chairman
ShapeBlue
 
PPTX
Extensions Framework (XaaS) - Enabling Orchestrate Anything
ShapeBlue
 
PDF
UiPath vs Other Automation Tools Meeting Presentation.pdf
Tracy Dixon
 
PDF
OpenInfra ID 2025 - Are Containers Dying? Rethinking Isolation with MicroVMs.pdf
Muhammad Yuga Nugraha
 
PDF
CIFDAQ Market Insight for 14th July 2025
CIFDAQ
 
PDF
Apache CloudStack 201: Let's Design & Build an IaaS Cloud
ShapeBlue
 
PPTX
Top Managed Service Providers in Los Angeles
Captain IT
 
PDF
Productivity Management Software | Workstatus
Lovely Baghel
 
PDF
TrustArc Webinar - Data Privacy Trends 2025: Mid-Year Insights & Program Stra...
TrustArc
 
PPTX
Building a Production-Ready Barts Health Secure Data Environment Tooling, Acc...
Barts Health
 
PDF
Building Resilience with Digital Twins : Lessons from Korea
SANGHEE SHIN
 
PDF
Novus-Safe Pro: Brochure-What is Novus Safe Pro?.pdf
Novus Hi-Tech
 
PPTX
Machine Learning Benefits Across Industries
SynapseIndia
 
PDF
Generative AI in Healthcare: Benefits, Use Cases & Challenges
Lily Clark
 
PDF
Market Wrap for 18th July 2025 by CIFDAQ
CIFDAQ
 
PDF
Lecture A - AI Workflows for Banking.pdf
Dr. LAM Yat-fai (林日辉)
 
Lecture 5 - Agentic AI and model context protocol.pptx
Dr. LAM Yat-fai (林日辉)
 
Simplifying End-to-End Apache CloudStack Deployment with a Web-Based Automati...
ShapeBlue
 
Building and Operating a Private Cloud with CloudStack and LINBIT CloudStack ...
ShapeBlue
 
Women in Automation Presents: Reinventing Yourself — Bold Career Pivots That ...
DianaGray10
 
Meetup Kickoff & Welcome - Rohit Yadav, CSIUG Chairman
ShapeBlue
 
Extensions Framework (XaaS) - Enabling Orchestrate Anything
ShapeBlue
 
UiPath vs Other Automation Tools Meeting Presentation.pdf
Tracy Dixon
 
OpenInfra ID 2025 - Are Containers Dying? Rethinking Isolation with MicroVMs.pdf
Muhammad Yuga Nugraha
 
CIFDAQ Market Insight for 14th July 2025
CIFDAQ
 
Apache CloudStack 201: Let's Design & Build an IaaS Cloud
ShapeBlue
 
Top Managed Service Providers in Los Angeles
Captain IT
 
Productivity Management Software | Workstatus
Lovely Baghel
 
TrustArc Webinar - Data Privacy Trends 2025: Mid-Year Insights & Program Stra...
TrustArc
 
Building a Production-Ready Barts Health Secure Data Environment Tooling, Acc...
Barts Health
 
Building Resilience with Digital Twins : Lessons from Korea
SANGHEE SHIN
 
Novus-Safe Pro: Brochure-What is Novus Safe Pro?.pdf
Novus Hi-Tech
 
Machine Learning Benefits Across Industries
SynapseIndia
 
Generative AI in Healthcare: Benefits, Use Cases & Challenges
Lily Clark
 
Market Wrap for 18th July 2025 by CIFDAQ
CIFDAQ
 
Lecture A - AI Workflows for Banking.pdf
Dr. LAM Yat-fai (林日辉)
 

파이썬 개발환경 구성하기의 끝판왕 - Docker Compose

  • 1. 1
  • 2. 2
  • 3. 3
  • 4. 4
  • 6. 6
  • 7. $ pip install -r requirements.txt 7
  • 8. 8
  • 9. $ pip install -r requirements.txt ... build/temp.macosx-10.11-x86_64-3.5/_openssl.c:400:10: fatal error: 'openssl/aes.h' file not found #include <openssl/aes.h> ^ 1 error generated. error: command 'clang' failed with exit status 1 9
  • 10. ... ld: library not found for -lpq collect2: ld returned 1 exit status ld: library not found for -lpq collect2: ld returned 1 exit status error: command 'clang' failed with exit status 1 10
  • 11. ... building '_imaging' extension creating build/temp.macosx-10.8-intel-2.7 creating build/temp.macosx-10.8-intel-2.7/libImaging ... unable to execute clang: No such file or directory error: command 'clang' failed with exit status 1 11
  • 12. ... Skipping installation of /Library/Python/2.7/site-packages/ virtualenvwrapper/init.py (namespace package) copying virtualenvwrapper/hook_loader.py -> /Library/Python/ 2.7/site-packages/virtualenvwrapper error: /Library/Python/2.7/site-packages/virtualenvwrapper: Permission denied 12
  • 14. $ sudo pip install xxx 14
  • 15. $ brew install xxx 15
  • 16. ImportError: No module named xxx 16
  • 18. 18
  • 19. 19
  • 20. 20
  • 21. 21
  • 22. 22
  • 23. 23
  • 24. 24
  • 25. 25
  • 26. 26
  • 27. 27
  • 28. 28
  • 29. 29
  • 30. 30
  • 31. 31
  • 32. 32
  • 33. 33
  • 34. 34
  • 35. $ docker run -it python:3.7.0b4-stretch Unable to find image 'python:3.7.0b4-stretch' locally 3.7.0b4-stretch: Pulling from library/python cc1a78bfd46b: Extracting 16.52MB/45.32MB 6861473222a6: Download complete 7e0b9c3b5ae0: Download complete 3ec98735f56f: Downloading 14.75MB/50.03MB 9b311b87a021: Downloading 57.12MB/213.2MB 048165938570: Download complete b98bafe8d054: Pulling fs layer 9e173e93364f: Pulling fs layer 279629a74d4e: Waiting 35
  • 36. $ docker run -it python:3.7.0b4-stretch Unable to find image 'python:3.7.0b4-stretch' locally 3.7.0b4-stretch: Pulling from library/python cc1a78bfd46b: Pull complete 6861473222a6: Pull complete 7e0b9c3b5ae0: Pull complete 3ec98735f56f: Pull complete 9b311b87a021: Pull complete 048165938570: Pull complete b98bafe8d054: Pull complete 9e173e93364f: Pull complete 279629a74d4e: Pull complete Digest: sha256:4b4314d7020b5b2730ddc1fbe5be3a6f2f6cd2478156bc652a37bec012ff89dd Status: Downloaded newer image for python:3.7.0b4-stretch Python 3.7.0b4 (default, May 5 2018, 02:57:38) [GCC 6.3.0 20170516] on linux Type "help", "copyright", "credits" or "license" for more information. >>> 36
  • 37. 37
  • 38. 38
  • 39. 39
  • 40. $ docker run -it python:3 Python 3.6.5 (default, May 5 2018, 03:09:35) [GCC 4.9.2] on linux Type "help", "copyright", "credits" or "license" for more information. >>> 1 + 1 2 >>> 40
  • 41. $ docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 4fb53528e038 python:3 "python3" 2 seconds ago Up 1 second flamboyant_lichterman $ docker logs 4fb53528e038 Python 3.6.5 (default, May 5 2018, 03:09:35) [GCC 4.9.2] on linux Type "help", "copyright", "credits" or "license" for more information. >>> 1 + 1 2 $ 41
  • 42. $ docker exec -it 4fb53528e038 bash root@4fb53528e038:/# ls bin dev home lib64 mnt proc run srv tmp var boot etc lib media opt root sbin sys usr root@4fb53528e038:/# 42
  • 43. $ docker run -it python:3 $ docker logs 4fb53528e038 python:3 4fb53528e038 43
  • 44. $ docker run -it python:3 Python 3.6.5 (default, May 5 2018, 03:09:35) [GCC 4.9.2] on linux Type "help", "copyright", "credits" or "license" for more information. >>> exit() $ docker run -it python:3 bash root@b1ae1f2de579:/# 44
  • 45. $ docker run -it --env CONF_NAME=pycon_seminar python:3 bash root@04cc7afe7362:/# echo $CONF_NAME pycon_seminar root@04cc7afe7362:/# 45
  • 46. $ ls djangosample __init__.py settings.py urls.py wsgi.py $ docker run -it --volume `pwd`/djangosample:/djangosample python:3 bash root@04cc7afe7362:/# ls /djangosample __init__.py settings.py urls.py wsgi.py root@04cc7afe7362:/# 46
  • 47. 47
  • 48. 48
  • 50. 50
  • 51. 51
  • 52. FROM python:3 RUN apt-get update && apt-get -y install libpq-dev ADD ./djangosample /app/ WORKDIR /app CMD ["python", "manage.py", "runserver", "0:8000"] 52
  • 53. $ git clone https://github.com/raccoonyy/django-sample-for-docker-compose $ cd django-sample-for-docker-compose $ docker build -t my-django . 53
  • 54. $ docker run -d --env POSTGRES_DB=djangosample --env POSTGRES_USER=sampleuser --env POSTGRES_PASSWORD=samplesecret --name db postgres $ docker run -it --env DJANGO_DEBUG=True --env DJANGO_DB_HOST=postgres --link db:postgres --publish 8000:8000 my-django $ open http://127.0.0.1:8000 54
  • 55. --name db db --link db:postgres db postgres --publish 8000:8000 55
  • 56. $ mkdir data $ docker run -d --env POSTGRES_DB=djangosample --env POSTGRES_USER=sampleuser --env POSTGRES_PASSWORD=samplesecret --name db --volume data:/var/lib/postgresql/data <-- New! postgres 56
  • 57. $ docker run -d --env POSTGRES_DB=djangosample --env POSTGRES_USER=sampleuser --env POSTGRES_PASSWORD=samplesecret --name db --volume `pwd`/data:/var/lib/postgresql/data --rm <-- New! postgres 57
  • 58. $ docker run -it --env DJANGO_DEBUG=True --env DJANGO_DB_HOST=postgres --link my-postgres:postgres --publish 8000:8000 --volume `pwd`:/app <-- New! my-django 58
  • 59. 59
  • 61. version: '3' volumes: django_sample_db_dev: {} services: db: image: postgres volumes: - django_sample_db_dev:/var/lib/postgresql/data environment: - POSTGRES_DB=sampledb - POSTGRES_USER=sampleuser - POSTGRES_PASSWORD=samplesecret django: build: context: . dockerfile: ./compose/django/Dockerfile-dev environment: - DJANGO_DEBUG=True - DJANGO_DB_HOST=postgres - DJANGO_DB_PORT=5432 - DJANGO_DB_NAME=sampledb - DJANGO_DB_USERNAME=sampleuser - DJANGO_DB_PASSWORD=samplesecret - DJANGO_SECRET_KEY=dev_secret_key ports: - "8000:8000" depends_on: - db links: - db:postgres command: ["/wait-for-it.sh", "postgres:5432", "-t", "10", "--", "/start-dev.sh"] volumes: - ./djangosample:/app/djangosample 61
  • 62. version: '3' volumes: django_sample_db_dev: {} services: db: image: postgres volumes: - django_sample_db_dev:/var/lib/postgresql/data environment: - POSTGRES_DB=sampledb - POSTGRES_USER=sampleuser - POSTGRES_PASSWORD=samplesecret 62
  • 63. django: build: context: . dockerfile: ./compose/django/Dockerfile-dev environment: - DJANGO_DEBUG=True - DJANGO_DB_HOST=postgres - DJANGO_DB_PORT=5432 - DJANGO_DB_NAME=sampledb - DJANGO_DB_USERNAME=sampleuser - DJANGO_DB_PASSWORD=samplesecret - DJANGO_SECRET_KEY=dev_secret_key ports: - "8000:8000" depends_on: - db links: - db:postgres volumes: - ./:/app/ 63
  • 64. python:3 image build --volume volumes --env environment --link links depends_on --publish ports 64
  • 65. 65
  • 66. $ docker-compose ps Name Command State Ports --------------------------------------------------------------------------------------------------------- django-sample-for-docker-compose_db_1 docker-entrypoint.sh postgres Up 5432/tcp django-sample-for-docker- bash -c python manage.py m ... Up 0.0.0.0:8000->8000/tcp compose_django_1 66
  • 67. $ docker-compose up $ docker-compose up -d 67
  • 68. $ docker-compose logs [service name] $ docker-compose logs -f [service name] 68
  • 69. $ docker-compose exec django bash root@3707e50b0c9a:/app# 69
  • 70. $ docker-compose down Stopping django-sample-for-docker-compose_django_1 ... done Stopping django-sample-for-docker-compose_db_1 ... done Removing django-sample-for-docker-compose_django_1 ... done Removing django-sample-for-docker-compose_db_1 ... done Removing network django-sample-for-docker-compose_default $ docker-compose down -v 70
  • 71. 71
  • 72. # docker-compose.yml django: ... stdin_open: true tty: true $ docker attach CONTAINER_ID 72
  • 73. bash command # docker-compose.yml service: ... django: ... command: - bash - -c - | python manage.py migrate python manage.py runserver 0:8000 73
  • 75. $ docker-compose up --build $ docker-compose up --force-recreate 75
  • 76. 76
  • 77. 77
  • 78. 78
  • 79. 79
  • 80. 80