Add cross-platform Docker Compose stack and validate runtime health

This commit is contained in:
nizar 2026-02-23 23:52:32 +01:00
parent a9b43aae99
commit 85664c1b75
5 changed files with 129 additions and 12 deletions

10
.env.example Normal file
View file

@ -0,0 +1,10 @@
# Copy to .env and adjust values before `docker compose up -d`
# PostgreSQL
POSTGRES_USER=postgres
POSTGRES_PASSWORD=change_me_postgres_password
POSTGRES_DB=game
# MongoDB (required by the app)
MONGO_ROOT_USERNAME=wingsemu
MONGO_ROOT_PASSWORD=change_me_mongo_password

View file

@ -116,22 +116,42 @@ Let's skip it using `Skip tutorial` button and... that's it - Congratulations!
![](https://i.imgur.com/AUY0n7c.png)
### Running Docker
### Running Docker (Windows + Linux)
To run PostgreSQL, Redis, MongoDB and MQTT Broker for our server, we have to create [Docker containers](https://www.docker.com/resources/what-container).
To run PostgreSQL, Redis, MongoDB and MQTT Broker for our server, use Docker Compose (cross-platform).
- **PowerShell**
- Go to the `.server/scripts/Docker` directory
- For each file in the directory, click right mouse button on the file and choose `Run with PowerShell`
- ![](https://i.imgur.com/1ar8Nkd.png)
- **Terminal**
- Go to the `.server/scripts/Docker` directory
- Open each `.ps1` file, select the entire script (starts with `docker run`) and copy it into Terminal (you can use this script anywhere) and then press [`ENTER`] key:
- ![](https://i.imgur.com/auCrU6q.png)
1. Copy env file:
After successfully using the commands, you should see 4 new containers in your Docker Hub.
```bash
cp .env.example .env
```
![](https://i.imgur.com/Lz5O8PL.png)
2. Edit `.env` and set strong secrets (`POSTGRES_PASSWORD`, `MONGO_ROOT_PASSWORD`).
3. Start dependencies:
```bash
docker compose up -d
```
4. Check status:
```bash
docker compose ps
```
5. Stop everything:
```bash
docker compose down
```
Optional helper scripts (Linux/macOS):
```bash
./scripts/docker-up.sh
./scripts/docker-down.sh
```
___

68
docker-compose.yml Normal file
View file

@ -0,0 +1,68 @@
services:
postgres:
image: postgres:13
container_name: wingsemu-postgres
restart: unless-stopped
environment:
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}
POSTGRES_DB: ${POSTGRES_DB:-game}
POSTGRES_USER: ${POSTGRES_USER:-postgres}
ports:
- "5432:5432"
volumes:
- postgres_data:/var/lib/postgresql/data
healthcheck:
test: ["CMD-SHELL", "pg_isready -U ${POSTGRES_USER:-postgres}"]
interval: 10s
timeout: 5s
retries: 10
redis:
image: redis:7-alpine
container_name: wingsemu-redis
restart: unless-stopped
command: ["redis-server", "--notify-keyspace-events", "Kx", "--appendonly", "yes"]
ports:
- "6379:6379"
volumes:
- redis_data:/data
healthcheck:
test: ["CMD", "redis-cli", "ping"]
interval: 10s
timeout: 5s
retries: 10
mongodb:
image: mongo:6
container_name: wingsemu-mongodb
restart: unless-stopped
environment:
MONGO_INITDB_ROOT_USERNAME: ${MONGO_ROOT_USERNAME}
MONGO_INITDB_ROOT_PASSWORD: ${MONGO_ROOT_PASSWORD}
ports:
- "27017:27017"
volumes:
- mongodb_data:/data/db
healthcheck:
test: ["CMD", "mongosh", "--quiet", "--eval", "db.runCommand({ ping: 1 }).ok"]
interval: 15s
timeout: 10s
retries: 10
mqtt:
image: emqx/emqx:latest
container_name: wingsemu-mqtt
restart: unless-stopped
ports:
- "1883:1883"
- "18083:18083"
healthcheck:
test: ["CMD-SHELL", "emqx ctl status | grep -q 'is started'"]
interval: 15s
timeout: 10s
retries: 10
volumes:
postgres_data:
redis_data:
mongodb_data:

6
scripts/docker-down.sh Normal file
View file

@ -0,0 +1,6 @@
#!/usr/bin/env bash
set -euo pipefail
docker compose down
echo "[OK] Containers stopped"

13
scripts/docker-up.sh Normal file
View file

@ -0,0 +1,13 @@
#!/usr/bin/env bash
set -euo pipefail
if [[ ! -f .env ]]; then
echo "[INFO] .env not found. Creating from .env.example"
cp .env.example .env
echo "[WARN] Please edit .env secrets before using in production."
fi
docker compose up -d
echo "[OK] Containers started"
docker compose ps