harbor run -t LiteCoder/nginx-node-mariadb-composeharbor download LiteCoder/nginx-node-mariadb-composeDeploy a containerized web stack under /app where Nginx reverse-proxies to two Node.js API services backed by a shared MariaDB database, all orchestrated via Docker Compose.
/app/app/
├── docker-compose.yml
├── nginx.conf
├── package.json
├── Dockerfile
├── api.js # Service A source
└── api-b.js # Service B source
Service A (api.js)
0.0.0.0:3000GET / returns HTTP 200 with Content-Type: application/json and body:
{"service":"A"}
Service B (api-b.js)
GET / returns:
{"service":"B"}
Dockerfile
Dockerfile that can build both Service A and Service B images.API_FILE) to select which source file (api.js or api-b.js) is used inside the container.MariaDB
mariadb image.MYSQL_ROOT_PASSWORD: rootpassMYSQL_DATABASE: appdbMYSQL_USER: appuserMYSQL_PASSWORD: apppass./db on the host.Nginx
nginx.conf that defines an upstream block containing api-a:3000 and api-b:3000.80.The docker-compose.yml must define exactly four services:
| Service Name | Image / Build | Exposed Port (host) |
|---|---|---|
db |
mariadb (official) |
none required |
api-a |
Built from Dockerfile with build arg selecting api.js |
none required on host |
api-b |
Built from Dockerfile with build arg selecting api-b.js |
none required on host |
nginx |
nginx (official) |
80:80 |
api-a and api-b must depend on db.nginx must depend on api-a and api-b.docker compose up -d (or docker-compose up -d) from /app starts all four containers successfully.http://localhost:80/ return valid JSON with either {"service":"A"} or {"service":"B"}.http://localhost:80/ distribute across both services (round-robin).docker compose down && docker compose up -d works cleanly.