-
Notifications
You must be signed in to change notification settings - Fork 2
/
docker-compose.yml
99 lines (93 loc) · 3.53 KB
/
docker-compose.yml
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
version: '3.8'
services:
scrappers:
build:
context: ./scrappers
dockerfile: Dockerfile
depends_on:
db:
condition: service_healthy # Wait until the health check passes
ports:
- "5000:5000" # Port 5000 on host to port 5000 on container
volumes:
- ./scrappers:/app # Mount scrappers directory for persistence
env_file:
- .env # Add environment variables from file
environment:
# Credentials used to connect to db from db.py __init__ method
# Located in root .env file
- DB_HOST=${DB_HOST_DOCKER}
- DB_PORT=${DB_PORT}
- DB_USER=${DB_USER}
- DB_PASS=${DB_PASS}
- DB_NAME=${DB_NAME}
# Add email credentials for notifier?
- GMAIL_CRED=${GMAIL_CRED}
db:
image: mysql:8.0.35
command: --default-authentication-plugin=mysql_native_password
volumes:
# Mount SQL scripts for database initialization
- ./db/sql/init_sql_scripts:/docker-entrypoint-initdb.d
env_file:
- .env # Add environment variables from file
ports:
- "3307:3306" # Port 3307 on host to port 3306 on container
environment:
- MYSQL_ROOT_PASSWORD=${DB_PASS}
healthcheck:
test: ["CMD", "mysql", "-h", "localhost", "-u", "root", "-p${DB_PASS}", "-e", "SELECT 1"]
timeout: 20s
retries: 10
redis:
image: redis:alpine
ports:
- "6380:6379" # Port 6380 on host to port 6379 on container
backend:
command: sh -c "python3 manage.py migrate --noinput && python manage.py runserver"
build:
context: ./backend
dockerfile: Dockerfile
volumes:
- ./backend:/app # Mount backend directory for persistence
depends_on:
db:
condition: service_healthy # Wait until the health check passes
ports:
- "8000:8000" # Port 8000 on host to port 8000 on container
env_file:
- .env # Add environment variables from file
environment:
# Credentials used to connect to db from settings.py
# Located in root .env file
- DB_HOST=${DB_HOST_DOCKER}
- DB_PORT=${DB_PORT}
- DB_USER=${DB_USER}
- DB_PASS=${DB_PASS}
- DB_NAME=${DB_NAME}
frontend:
build:
context: ./frontend
dockerfile: Dockerfile
depends_on:
db:
condition: service_healthy # Wait until the health check passes
ports:
- "5173:5173" # Port 5173 on host to port 5173 on container
volumes:
- ./frontend:/app # Mount frontend directory for persistence
env_file:
- .env # Add environment variables from file
# Notes
# ---------------------------------------------------------------------------------------------
# 1. The db host name is 'db' because docker compose creates the same network
# for all services in the docker-compose.yml file
# https://docs.docker.com/compose/networking/
# The db port is 3306 because that is the MySQL port in the container specified in the ports section
# And since we are trying to connect the 2 containers, we use the container port
# The db might take a while to start up, so the app might fail to connect to the db at first
# If that happens, just restart the app container --> See README.md for more details
# ---------------------------------------------------------------------------------------------
# 2. The db container mounts the init_sql_scripts directory to the /docker-entrypoint-initdb.d directory
# in the container. This is where MySQL looks for SQL scripts to run when the container starts up
# to initialize the database. The scripts are run in alphabetical order.