-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdocker-compose.yml
65 lines (61 loc) · 3.48 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.7'
services: # the different images that will be running as containers
nginx: # service name
build: ./nginx # location of the dockerfile that defines the nginx image. The dockerfile will be used to spin up an image during the build stage
ports:
- 1339:80 # map the external port 1339 to the internal port 80. Any traffic from 1339 externally will be passed to port 80 of the NGINX container. To access this app, one would use an address such as 0.0.0.0:1339
volumes: # static storages provisioned since django does not handle static files in production
- static_volume:/home/app/microservice/static # provide a space for static files
depends_on:
- web # will only start if web is up and running
restart: "on-failure" # restart service when it fails
web: # service name
build: . #build the image for the web service from the dockerfile in parent directory.
# command directive passes the parameters to the service and they will be executed by the service. In this example, these are django commands which will be executed in the container where django lives.
command: sh -c "python manage.py makemigrations &&
python manage.py migrate &&
gunicorn microservice_sample_app.wsgi:application --bind 0.0.0.0:${APP_PORT}" # Django commands to run app using gunicorn
volumes:
- .:/microservice # map data and files from parent directory in host to microservice directory in docker container
- static_volume:/home/app/microservice/static
env_file: # file where env variables are stored. Used as best practice so as not to expose secret keys
- .env # name of the env file
image: microservice_app # name of the image
expose: # expose the port to other services defined here so that they can access this service via the exposed port. In the case of Django, this is 8000 by default
- ${APP_PORT} # retrieved from the .env file
restart: "on-failure"
depends_on: # cannot start if db service is not up and running
- db
db: # service name
image: postgres:11-alpine # image name of the postgres database. during build, this will be pulled from dockerhub and a container spun up from it
volumes:
- ./init.sql:/docker-entrypoint-initdb.d/init.sql
- postgres_data:/var/lib/postgresql/data/
environment: # access credentials from the .env file
- POSTGRES_PASSWORD=${POSTGRES_PASSWORD}
- POSTGRES_DB=${DB_NAME}
- PGPORT=${DB_PORT}
- POSTGRES_USER=${POSTGRES_USER}
restart: "on-failure"
rabbitmq:
image: rabbitmq:3-management-alpine # image to be pulled from dockerhub during building
container_name: rabbitmq # container name
volumes: # assign static storage for rabbitmq to run
rabbitmq: - ./.docker/rabbitmq/etc/:/etc/rabbitmq/
- ./.docker/rabbitmq/data/:/var/lib/rabbitmq/
rabbitmq_logs: - ./.docker/rabbitmq/logs/:/var/log/rabbitmq/
environment: # environment variables from the referenced .env file
RABBITMQ_ERLANG_COOKIE: ${RABBITMQ_ERLANG_COOKIE}
# auth cretendials
RABBITMQ_DEFAULT_USER: ${RABBITMQ_DEFAULT_USER}
RABBITMQ_DEFAULT_PASS: ${RABBITMQ_DEFAULT_PASS}
ports: # map external ports to this specific container's internal ports
- 5672:5672
- 15672:15672
depends_on: # can only start if web service is running
- web
volumes:
postgres_data:
static_volume:
rabbitmq:
rabbitmq_logs: