feat: add network configuration to Docker compose

- Define a custom network 'net1' for services
- Attach services to 'net1' network
- Ensure connectivity between application components

This commit enhances the Docker Compose setup by introducing a
custom network. This isolation can help manage service
dependencies better and improve communication between services,
establishing clearer boundaries. It simplifies networking
configuration and lays the groundwork for further scaling
if needed.
This commit is contained in:
songtianlun 2025-01-23 10:44:37 +08:00
parent e1f9118ead
commit ccb48a387b

View File

@ -8,6 +8,8 @@ services:
- DATABASE_URL=postgresql://postgres:${PG_PASSWORD}@db:5432/db - DATABASE_URL=postgresql://postgres:${PG_PASSWORD}@db:5432/db
- RAILS_MASTER_KEY=${RAILS_MASTER_KEY} - RAILS_MASTER_KEY=${RAILS_MASTER_KEY}
- REDIS_URL=redis://redis:6379/0 - REDIS_URL=redis://redis:6379/0
networks:
- net1
depends_on: depends_on:
- db - db
- redis - redis
@ -20,6 +22,8 @@ services:
- DATABASE_URL=postgresql://postgres:${PG_PASSWORD}@db:5432/db - DATABASE_URL=postgresql://postgres:${PG_PASSWORD}@db:5432/db
- RAILS_MASTER_KEY=${RAILS_MASTER_KEY} - RAILS_MASTER_KEY=${RAILS_MASTER_KEY}
- REDIS_URL=redis://redis:6379/0 - REDIS_URL=redis://redis:6379/0
networks:
- net1
depends_on: depends_on:
- db - db
- redis - redis
@ -28,6 +32,8 @@ services:
image: postgres:16 image: postgres:16
volumes: volumes:
- ../taw_data/pg:/var/lib/postgresql/data - ../taw_data/pg:/var/lib/postgresql/data
networks:
- net1
environment: environment:
- POSTGRES_PASSWORD=${PG_PASSWORD} - POSTGRES_PASSWORD=${PG_PASSWORD}
- POSTGRES_DB=db - POSTGRES_DB=db
@ -36,4 +42,10 @@ services:
image: redis:7-alpine image: redis:7-alpine
volumes: volumes:
- ../taw_data/redis:/data - ../taw_data/redis:/data
networks:
- net1
command: redis-server --appendonly yes command: redis-server --appendonly yes
networks:
net1:
driver: bridge