-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdocker-compose.yml
65 lines (60 loc) · 3.72 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
version: '3.8' # docker-compose version
services: # defines the containers that will run as a part of your application
db: # this is 'db' service container
image: vedavault/mysql:latest # the mysql version on my dev environment becomes the base image of this container
volumes:
- mysql_data:/var/lib/mysql # mount 'mysql_data' to 'var/lib/mysql' inside the container this is where mysql stores data
restart: always # if container stops or crashes it will restart(policy)
environment: # sets environment variables inside the container, these will be used by mysql image to configure the DB
MYSQL_DATABASE: '${MYSQL_DATABASE_NAME}'
MYSQL_USER: '${MYSQL_USER}'
MYSQL_PASSWORD: '${MYSQL_PASSWORD}'
MYSQL_ROOT_PASSWORD: '${MYSQL_ROOT_PASSWORD}'
MYSQL_ALLOW_EMPTY_PASSWORD: 'yes'
MYSQL_ROOT_HOST: '%'
DEFAULT_AUTHENTICATION_PLUGIN: caching_sha2_password
ports:
- "3306:3306" # maps port 3306(on host) to 3306(inside the container) allowing u to connect mysql DB from the host
networks:
- backend # connect this container to a network, allows containers to communicate to each other using this network
command: --default-authentication-plugin=caching_sha2_password
redis:
image: vedavault/redis:latest # use the latest image of redis
restart: always # always restart when the container crashes or stops
ports:
- "6379:6379" # map port 6379(on host) to 6379(in the container)
networks:
- backend # connect this container to a network, allows containers to communicate to each other using this network
web:
build: . # build an image for this 'web' service using the 'Dockerfile' in the current directory
image: vedavault/web:latest
command: sh -c "wait-for-it --timeout=60 db:3306 && wait-for-it redis:6379 -- python manage.py makemigrations && python manage.py migrate &&
python manage.py create_admin_group &&
python manage.py runserver 0.0.0.0:8000" # this runs the django dev server on all network interfaces at port 8000
volumes:
- .:/app # mount the current directory to /app inside the container
ports:
- "8000:8000" # maps port 8000(on host) to 8000(inside the container)
depends_on:
- db # this ensures that 'db' service is started(running but not ready) before the 'web' service
- redis # this ensures that 'redis' service is started(running but not ready before the 'web' service
environment: # specify the environment variables inside the container which will be utilized by Django
DEBUG: '1'
DB_NAME: '${MYSQL_DATABASE_NAME}'
DB_USER: '${MYSQL_USER}'
DB_PASS: '${MYSQL_PASSWORD}'
DB_SERVICE: 'db'
DB_PORT: '3306'
AWS_ACCESS_KEY_ID: '${AWS_ACCESS_KEY_ID}'
AWS_SECRET_ACCESS_KEY: '${AWS_SECRET_ACCESS_KEY}'
AWS_S3_BUCKET_NAME: '${AWS_S3_BUCKET_NAME}'
AWS_S3_REGION_NAME: '${AWS_S3_REGION_NAME}'
AWS_S3_SIGNATURE_VERSION: '${AWS_S3_SIGNATURE_VERSION}'
REDIS_LOCATION: 'redis://redis:6379/1' # redis(1st one) is the scheme, redis(2nd one) with the help of Docker's internal DNS resolver, allows services to communicate with each other using service names as hostnames
networks:
- backend # connect this container to a network, allows containers to interact with each other
networks:
backend: # network named 'backend'
driver: bridge # this allows containers connected on the same network to communicate while isolating them from containers on other networks
volumes:
mysql_data: # declares a 'named volume'(for persistence) named 'mysql_data' which is used by 'db', Docker manages this volume independently of the life cycle of the containers, allowing data to persist across container restarts and rebuilds