Skip to content

Commit c5b3cf5

Browse files
committed
Enhance security and modularity of Docker Compose setup
- Removed `ports` for `gym-api` to prevent public exposure. - Added environment variables for flexible configuration: - Database connection, JWT settings, CORS, and API path. - Introduced `networks` for secure service communication: - `proxy_net` for external proxy access. - `internal_net` for private API-to-database communication. - Restricted `gym-db` access to `internal_net` only. - Removed manual `nginx` service; rely on Nginx Proxy Manager. - Replaced `volumes` with `networks` at the root level.
1 parent af8a5cb commit c5b3cf5

File tree

1 file changed

+19
-13
lines changed

1 file changed

+19
-13
lines changed

docker-compose.yml

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,23 @@ services:
55
build:
66
context: .
77
dockerfile: Dockerfile
8-
# REMOVED: ports: - "8080:8080" <-- We don't expose this to the public internet anymore
98
environment:
109
- ASPNETCORE_ENVIRONMENT=Production
10+
# Note: Consider using ${SA_PASSWORD} for better security instead of hardcoding
1111
- ConnectionStrings__DefaultConnection=Server=gym-db;Database=GymMasterDb;User Id=sa;Password=Gymdb2025@2025;TrustServerCertificate=True;
12+
- JWT__Secret=${JWT_SECRET}
13+
- JWT__Issuer=${DOMAIN_NAME}
14+
- JWT__Audience=${DOMAIN_NAME}
15+
- JWT__TokenValidityInMinutes=60
16+
- JWT__RefreshTokenValidityInMinutes=1440
17+
- AppConfig__CorsOrigins=${DOMAIN_NAME},http://localhost:5173,https://localhost:7077
18+
- AppConfig__ApiVirtualPath=${DOMAIN_NAME}
1219
depends_on:
1320
- gym-db
1421
restart: always
22+
networks:
23+
- proxy_net # connects to the internet (via Proxy Manager)
24+
- internal_net # connects to the database
1525

1626
# 2. SQL Server Database
1727
gym-db:
@@ -22,17 +32,13 @@ services:
2232
volumes:
2333
- sql_data:/var/opt/mssql
2434
restart: always
35+
networks:
36+
- internal_net # Only accessible by the API, safe from the internet!
2537

26-
# 3. Nginx Reverse Proxy (NEW)
27-
nginx:
28-
image: nginx:alpine
29-
ports:
30-
- "80:80" # Opens Port 80 on the VPS
31-
volumes:
32-
- ./nginx/default.conf:/etc/nginx/conf.d/default.conf
33-
depends_on:
34-
- gym-api
35-
restart: always
38+
# REMOVED: The manual 'nginx' service.
39+
# Nginx Proxy Manager is already running separately and handles Port 80.
3640

37-
volumes:
38-
sql_data:
41+
networks:
42+
proxy_net:
43+
external: true # This network must already exist (docker network create proxy_net)
44+
internal_net: # This creates a private link between API and DB

0 commit comments

Comments
 (0)