From 3f033071f78f33cb300ccf073334266066afbcd1 Mon Sep 17 00:00:00 2001 From: "M.Lotfi" Date: Wed, 14 Oct 2026 08:48:15 +0330 Subject: [PATCH] Fix some for docker --- .env.example | 3 ++- DOCKER.md | 7 +++++++ docker-compose.yml | 12 +++++++----- 3 files changed, 16 insertions(+), 6 deletions(-) diff --git a/.env.example b/.env.example index dee8b96..4b39060 100644 --- a/.env.example +++ b/.env.example @@ -3,7 +3,8 @@ POSTGRES_USER=postgres POSTGRES_PASSWORD=postgres POSTGRES_DB=goldbank -# Host port exposed for PostgreSQL (used by docker-compose db service) +# Host port for PostgreSQL. Each copy of this stack on the same machine +# must use a different port (the apps talk to hostname "db", not this port). EXTERNAL_DB_PORT=5432 # Prisma connection string (inside Docker network use hostname "db") diff --git a/DOCKER.md b/DOCKER.md index 6b3e6de..2515837 100644 --- a/DOCKER.md +++ b/DOCKER.md @@ -33,6 +33,13 @@ DATABASE_URL=postgresql://goldbank:...@db:5432/goldbank?schema=public PORT=3000 ``` +A second copy on the **same server** is a separate Dokploy application (its own +domains, passwords, and `JWT_SECRET`). Do not set `container_name` in this file: +those names are global in Docker, and a fixed `goldbank_db` collides with the +first copy. Give the second app its own `EXTERNAL_DB_PORT` (for example `5434` +if `5433` is already taken). Volumes stay separate because Dokploy uses a +different Compose project name for each application. + ## Domains (container ports) | Service | Domain | Port | diff --git a/docker-compose.yml b/docker-compose.yml index 41a7f14..b46240d 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -3,11 +3,17 @@ services: db: image: docker.arvancloud.ir/postgres:15-alpine - container_name: goldbank_db + # No container_name. Docker container names are global on the host, so a + # fixed name (goldbank_db) makes a second Dokploy app of this stack fail + # with "container name already in use". Compose names each container from + # the project name, which Dokploy sets uniquely per application. environment: POSTGRES_USER: ${POSTGRES_USER:-postgres} POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:-postgres} POSTGRES_DB: ${POSTGRES_DB:-goldbank} + # Host port only. The apps use hostname "db" inside the compose network. + # Two copies on one machine must publish different host ports; set + # EXTERNAL_DB_PORT on the second Dokploy app (5432 stays the local default). ports: - "${EXTERNAL_DB_PORT:-5432}:5432" volumes: @@ -23,7 +29,6 @@ services: build: context: ./apps/api dockerfile: Dockerfile - container_name: goldbank_api # Prisma connects on module init, so a not-yet-ready DB crash-loops the API. depends_on: db: @@ -110,7 +115,6 @@ services: build: context: ./apps/admin-panel dockerfile: Dockerfile - container_name: goldbank_admin_panel # No host ports — Dokploy/Traefik routes by domain to container port 80 expose: - "80" @@ -122,7 +126,6 @@ services: build: context: ./apps/user-app dockerfile: Dockerfile - container_name: goldbank_user_app # No host ports — Dokploy/Traefik routes by domain to container port 80 expose: - "80" @@ -135,7 +138,6 @@ services: build: context: ./apps/user-app-v2 dockerfile: Dockerfile - container_name: goldbank_user_app_v2 expose: - "80" restart: unless-stopped