-
Notifications
You must be signed in to change notification settings - Fork 0
/
docker-compose.yml
53 lines (47 loc) · 1.61 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
services:
# service-1: web-app (this is our fast-api web-app)
web-app:
build: .
image: user-api
env_file:
- .env # set all the environment variables from the .env file to the container
container_name: user-api-app
command: flask --app src/app.py run --host 0.0.0.0 #[ this will replace CMD command in the Dockerfile ]
ports:
- 5001:5000
volumes:
- ./src:/app/src # map the local directory to the container directory (for live code reloading) [NOTE: this replaces any COPY command in the Dockerfile]
depends_on:
- postgres # this will wait for the serviceName to be up before starting this service
- redis
networks:
- my-network
# service-2: db (this is our postgres database)
postgres:
image: postgres:16
container_name: user-api-db
environment:
POSTGRES_USER: ${DB_USER} # load DB_USER env variable from .env file
POSTGRES_PASSWORD: ${DB_PASSWORD} # load DB_PASSWORD env variable from .env file
POSTGRES_DB: user_db
ports:
- 5432:5432
networks:
- my-network
# service-3: redis (this is our Redis cache)
redis:
image: redis/redis-stack:latest
container_name: user-api-redis
ports:
- 6379:6379
networks:
- my-network
# Define the network
networks:
my-network:
name: user-api-network
driver: bridge
# Now, we can run the following command to start the services:
# docker-compose up
# This will start the services defined in the docker-compose.yml file.
# Now, we can access the web-app at http://localhost:5001 and the database at http://localhost:5432