Architecture
Client
↓
Port 27017 (MongoDB protocol)
↓
FerretDB container
↓
PostgreSQL container (internal Docker network)
↓
Persistent storage directory
FerretDB translates MongoDB wire protocol requests into PostgreSQL queries internally.
PostgreSQL is not publicly exposed.
Ports
- 27017/tcp → Public MongoDB-compatible endpoint
- 5432/tcp → Internal PostgreSQL (not exposed externally)
Access
Credentials reference: /root/ferretdb/.env
Install client if needed:
apt install -y mongodb-mongosh
Connect with authentication:
mongosh "mongodb://<USERNAME>:<PASSWORD>@<SERVER_IP>:27017/<DATABASE>?authSource=postgres"
Important Files & Directories
- Install directory:
/root/ferretdb - Compose file:
/root/ferretdb/docker-compose.yml - Environment file:
/root/ferretdb/.env - PostgreSQL data directory:
/root/ferretdb/data
Service Management
Check status:
docker ps
View logs:
docker compose -f /root/ferretdb/docker-compose.yml logs -f
Restart services:
docker compose -f /root/ferretdb/docker-compose.yml restart
Common MongoDB Commands
List databases:
show dbs
Switch database:
use postgres
List collections:
show collections
View documents:
db.collection_name.find()
Insert document:
db.collection_name.insertOne({ name: "example" })
Exit shell:
exit
Bind FerretDB to Localhost for Security
Authentication is enabled, but exposed database services are still a risk.
Edit: /root/ferretdb/.env
Change HOST=0.0.0.0 to HOST=127.0.0.1
Then apply changes:
docker compose -f /root/ferretdb/docker-compose.yml up -d
Now the service is not accessible externally.
Access using SSH port forwarding.
From your local machine:
ssh -L 27017:localhost:27017 root@<SERVER_IP>
Then connect locally:
mongosh "mongodb://<USERNAME>:<PASSWORD>@localhost:27017/<DATABASE>?authSource=postgres