chore(docker): publish ports only in development

docker-compose.yml is the production definition (deployed by Dokploy) and no
longer publishes any port: postgres, mongo, redis and the API are reachable
only on the compose network, and the web goes out through the platform's
proxy (domain → service web, port 80). The ports moved to
docker-compose.override.yml, which Compose loads automatically locally and
Dokploy (-f docker-compose.yml) does not.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-03 14:16:50 +02:00
parent bf0294a188
commit b2c9be72c3
5 changed files with 38 additions and 13 deletions

View File

@@ -0,0 +1,14 @@
# Development only: published ports, so `npx nx serve api` / `npx nx serve web` and your tools
# can reach the containers. Compose loads this file automatically with docker-compose.yml;
# production (Dokploy) runs `-f docker-compose.yml` alone and publishes nothing.
services:
web:
ports: ['8080:80']
api:
ports: ['3000:3000']
postgres:
ports: ['5432:5432']
mongo:
ports: ['27017:27017']
redis:
ports: ['6379:6379']

View File

@@ -1,4 +1,8 @@
# TaskStream: web + API + infrastructure. # TaskStream: web + API + infrastructure — production definition (Dokploy deploys this file).
# No ports are published here: services only talk over the compose network, and the web is
# exposed through the platform's proxy (Dokploy domain → service `web`, port 80).
#
# Locally, `docker compose` also loads docker-compose.override.yml, which publishes the ports:
# docker compose up -d --build → everything: web on http://localhost:8080 # docker compose up -d --build → everything: web on http://localhost:8080
# docker compose up -d postgres mongo redis → only infrastructure (then `npx nx serve api` / `npx nx serve web`) # docker compose up -d postgres mongo redis → only infrastructure (then `npx nx serve api` / `npx nx serve web`)
# #
@@ -11,7 +15,7 @@ services:
target: web target: web
secrets: [nexus_token] secrets: [nexus_token]
image: task-stream-web image: task-stream-web
ports: ['8080:80'] expose: ['80']
depends_on: depends_on:
api: { condition: service_healthy } api: { condition: service_healthy }
restart: unless-stopped restart: unless-stopped
@@ -22,7 +26,7 @@ services:
target: api target: api
secrets: [nexus_token] secrets: [nexus_token]
image: task-stream-api image: task-stream-api
ports: ['3000:3000'] expose: ['3000']
environment: environment:
POSTGRES_URL: postgres://taskstream:taskstream@postgres:5432/taskstream POSTGRES_URL: postgres://taskstream:taskstream@postgres:5432/taskstream
# No migrations yet: TypeORM creates the event store and lookup tables. # No migrations yet: TypeORM creates the event store and lookup tables.
@@ -50,7 +54,6 @@ services:
POSTGRES_USER: taskstream POSTGRES_USER: taskstream
POSTGRES_PASSWORD: taskstream POSTGRES_PASSWORD: taskstream
POSTGRES_DB: taskstream POSTGRES_DB: taskstream
ports: ['5432:5432']
volumes: [postgres-data:/var/lib/postgresql/data] volumes: [postgres-data:/var/lib/postgresql/data]
healthcheck: healthcheck:
test: ['CMD-SHELL', 'pg_isready -U taskstream'] test: ['CMD-SHELL', 'pg_isready -U taskstream']
@@ -59,7 +62,6 @@ services:
mongo: mongo:
image: mongo:8 image: mongo:8
ports: ['27017:27017']
volumes: [mongo-data:/data/db] volumes: [mongo-data:/data/db]
healthcheck: healthcheck:
test: ['CMD', 'mongosh', '--quiet', '--eval', 'db.adminCommand("ping")'] test: ['CMD', 'mongosh', '--quiet', '--eval', 'db.adminCommand("ping")']
@@ -69,7 +71,6 @@ services:
redis: redis:
image: redis:7-alpine image: redis:7-alpine
command: ['redis-server', '--appendonly', 'yes'] command: ['redis-server', '--appendonly', 'yes']
ports: ['6379:6379']
volumes: [redis-data:/data] volumes: [redis-data:/data]
healthcheck: healthcheck:
test: ['CMD', 'redis-cli', 'ping'] test: ['CMD', 'redis-cli', 'ping']

View File

@@ -9,13 +9,23 @@ docker compose logs -f api
docker compose down # parar (-v borra los datos) docker compose down # parar (-v borra los datos)
``` ```
| Servicio | Imagen | Puerto | Función | | Servicio | Imagen | Puerto en local | Función |
| ---------- | --------------------------- | ------ | ----------------------------------------------------------------------- | | ---------- | --------------------------- | --------------- | ----------------------------------------------------------------------- |
| `web` | `task-stream-web` (nginx) | 8080 | SPA y proxy de `/api` y `/graphql` (incluido el WebSocket) hacia la API | | `web` | `task-stream-web` (nginx) | 8080 | SPA y proxy de `/api` y `/graphql` (incluido el WebSocket) hacia la API |
| `api` | `task-stream-api` (Node 22) | 3000 | API NestJS | | `api` | `task-stream-api` (Node 22) | 3000 | API NestJS |
| `postgres` | postgres:17-alpine | 5432 | Event store y lookups | | `postgres` | postgres:17-alpine | 5432 | Event store y lookups |
| `mongo` | mongo:8 | 27017 | Read model | | `mongo` | mongo:8 | 27017 | Read model |
| `redis` | redis:7-alpine (AOF) | 6379 | Stream de eventos, pub/sub y caché de sesiones | | `redis` | redis:7-alpine (AOF) | 6379 | Stream de eventos, pub/sub y caché de sesiones |
### Producción y desarrollo
- **`docker-compose.yml`** es la definición de producción (la que despliega Dokploy) y **no publica puertos**: los
servicios solo se ven entre sí por la red de Compose. Hacia fuera solo sale la web, por el proxy de la plataforma
(en Dokploy: dominio → servicio `web`, puerto `80`). `web` y `api` declaran `expose` para documentarlo.
- **`docker-compose.override.yml`** publica los puertos de la tabla. Compose lo carga solo cuando se ejecuta sin `-f`,
es decir, en local; Dokploy usa `-f docker-compose.yml` y no lo lee.
Para probar en local exactamente lo de producción: `docker compose -f docker-compose.yml up -d --build`.
Todos tienen healthcheck; `web` espera a que `api` esté sana, y `api` a las tres bases de datos. Todos tienen healthcheck; `web` espera a que `api` esté sana, y `api` a las tres bases de datos.

Binary file not shown.

Binary file not shown.