-
Notifications
You must be signed in to change notification settings - Fork 1
/
dockerize.py
49 lines (39 loc) · 1.6 KB
/
dockerize.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# dockerize.py
# This file should be exactly what you produce after
# you finish the accompaning tutorial.
# (Make sure to change the repository directory in line 12)
from docker import from_env
import os
client = from_env()
# get paths
repo_dir = os.path.join('/absolute/path/to/tutorial', 'django-todo')
web_pth = os.path.join(repo_dir, 'web')
api_pth = os.path.join(repo_dir, 'api')
# build images
web_img, logs = client.images.build(path=web_pth, tag='web')
api_img, logs = client.images.build(path=api_pth, tag='api')
net_name = 'djang-net'
net = client.networks.create(name=net_name, driver='bridge')
# ports
api_ports = {'8000/tcp' : 8000}
web_ports = {'8080/tcp' : 8080}
web_env = ["HOST=0.0.0.0"]
# volumes
api_vol = {
os.path.join(repo_dir, 'api/django_todo') : { 'bind': '/usr/src/app', 'mode': 'rw'}
}
web_vol = {
os.path.join(repo_dir, 'web/vue-todo') : { 'bind' : '/usr/src/app', 'mode' : 'rw'}
}
db_vol = {
os.path.join(repo_dir, 'dbdata') : {'bind' : '/var/lib/postgresql/data'}
}
# launch
db = client.containers.run('postgres:10', detach=True, name='db',
network=net_name, volumes=db_vol)
api = client.containers.run(api_img, ports=api_ports, detach=True,
name='api', network=net_name, volumes=api_vol,
command="sh back.sh")
web = client.containers.run(web_img, ports=web_ports, detach=True,
name='web', network=net_name, volumes=web_vol,
environment=web_env, command="sh front.sh")