Adding databases to the Docker Compose landscape
Now, we have all of the source code in place. Before we can start up the microservice landscape and try out the new APIs together with the new persistence layer, we must start up some databases.
We will bring MongoDB and MySQL into the system landscape controlled by Docker Compose and add configuration to our microservices so that they can find their databases when running.
The Docker Compose configuration
MongoDB and MySQL are declared as follows in the Docker Compose configuration file, docker-compose.yml
:
mongodb:
image: mongo:6.0.4
mem_limit: 512m
ports:
- "27017:27017"
command: mongod
healthcheck:
test: "mongo --eval 'db.stats().ok'"
interval: 5s
timeout: 2s
retries: 60
mysql:
image: mysql:8.0.32
mem_limit: 512m
ports:
- "3306:3306"
environment:
- MYSQL_ROOT_PASSWORD=rootpwd
- MYSQL_DATABASE...