This simple recipe creates two new containers, one for MongoDB and one for Mongo Express.
Based on MongoDb from Docker Hub, ddev custom compose files and API Platform tutorial.
I'm using it on a Symfony 4 app with API Platform.
Steps to follow:
-
Install php-mongo extension by adding
webimage_extra_packages: [php-mongodb]
to your .ddev/config.yaml. -
Add extra file docker-compose.mongo.yaml
-
Require the Doctrine MongoDB ODM bundle
ddev composer require doctrine/mongodb-odm-bundle:^4.0.0@beta doctrine/mongodb-odm:^2.0.0@beta
-
In your application
.env
, set the connection string:MONGODB_URL=mongodb://db:db@mongo:27017 MONGODB_DB=api
Mongo Express will now be accessible from https://<site>.ddev.site:8081
Caveats:
- You can't define custom MongoDB configuration with this current setup.
- You can't use
ddev import-db
to import to mongo.
Contributed by @wtfred