-
Notifications
You must be signed in to change notification settings - Fork 0
/
compose.yaml
55 lines (50 loc) · 2.95 KB
/
compose.yaml
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
version: "3.8" # Specifies the version of the Docker Compose file format.
services: # Defines the services (containers) to be created.
database: # Service name for the PostgreSQL database.
image: postgres:latest # Uses the latest PostgreSQL image from Docker Hub.
restart: always # Automatically restarts the container if it stops.
container_name: swiftchat_postgres # Sets a specific name for the container.
environment: # Environment variables for PostgreSQL configuration.
POSTGRES_DB: ${POSTGRE_DB} # Database name from the .env file.
POSTGRES_USER: ${POSTGRE_USER} # User for the database from the .env file.
POSTGRES_PASSWORD: ${POSTGRE_PASSWORD} # Password for the database from the .env file.
ports:
- "5437:5432" # Maps port 5437 on the host to port 5432 in the container.
volumes: # Mounts volumes for data persistence.
- db:/var/lib/postgresql/data # Persistent storage for the database data.
- ./sql/init.sql:/docker-entrypoint-initdb.d/init.sql # Initializes the database with a script.
networks:
- swiftchat_network # Connects the container to a specified network.
redis: # Service name for the Redis cache.
image: redis:latest # Uses the latest Redis image from Docker Hub.
restart: always # Automatically restarts the container if it stops.
container_name: swiftchat_redis # Sets a specific name for the container.
ports:
- "6379:6379" # Maps port 6379 on the host to port 6379 in the container.
command: ["redis-server", "--requirepass", "${REDIS_PASSWORD}"] # Starts Redis with password protection.
volumes:
- redis:/data # Persistent storage for Redis data.
networks:
- swiftchat_network # Connects the container to a specified network.
swiftchat_api: # Service name for the API.
build: . # Builds the image from the Dockerfile in the current directory.
container_name: swiftchat_api # Sets a specific name for the container.
ports:
- "9000:9000" # Maps port 9000 on the host to port 9000 in the container.
restart: on-failure # Restarts the container only if it exits with a non-zero status.
depends_on: # Specifies dependency on other services.
- database # The API waits for the database to be ready.
- redis # The API waits for Redis to be ready.
environment: # Environment variables for the API.
- POSTGRE_HOST=swiftchat_postgres # Host for PostgreSQL (uses container name).
- REDIS_HOST=swiftchat_redis:6379 # Host for Redis with port.
env_file:
- .env # Loads environment variables from the .env file.
networks:
- swiftchat_network # Connects the container to a specified network.
volumes: # Defines named volumes for data persistence.
db: # Volume for PostgreSQL.
redis: # Volume for Redis.
networks: # Defines networks for service communication.
swiftchat_network: # Custom bridge network.
driver: bridge # Specifies the network driver.