Runs a MongoDB 8.0 instance in Docker with an external data folder and pre-configured users.
- Docker Desktop (Windows/Mac) or Docker Engine (Linux)
-
Copy
.envand set real passwords:MONGO_ROOT_USER=admin MONGO_ROOT_PASSWORD=your_root_password MONGO_DB=formpf3
Also update the app user password in init/01-create-user.js.
-
Start the container:
docker compose up -d
On first start, MongoDB will:
- Create the root admin using credentials from
.env - Run
init/01-create-user.jsto create the app-level userformpf3_user
Data is persisted in ./data/ on the host.
# Start in background
docker compose up -d
# Stop
docker compose down
# View logs
docker logs formpf3-mongo
# Open a Mongo shell inside the container (as root)
docker exec -it formpf3-mongo mongosh -u admin -p your_root_password --authenticationDatabase admin
# Rebuild from scratch (WARNING: deletes all data)
docker compose down
rm -rf ./data
docker compose up -dUse the app-level user (not root) in your connection string:
mongodb://formpf3_user:changeme_app@localhost:27017/formpf3
Ensure port 27017 is open in the server's firewall, then:
mongodb://formpf3_user:changeme_app@<server-ip>:27017/formpf3
Or connect with a GUI tool (Compass, Studio 3T, etc.) using the same host/port/credentials.
mongo-in-docker/
├── docker-compose.yml # Service definition
├── .env # Credentials (gitignored — never commit this)
├── .gitignore
├── data/ # MongoDB data files (gitignored)
├── logs/ # MongoDB log files (gitignored)
└── init/
└── 01-create-user.js # Runs once on first boot to create the app user
- The
init/scripts only run whendata/is empty (i.e. first boot or after a wipe). - To add more databases or users, add more
.jsfiles underinit/— they run in filename order. - The root user is for admin tasks only; use
formpf3_userfrom application code.