I want to run two mongo docker containers with docker compose. The mongo containers have same shared volumes with the docker host. When I ran it with docker compose, only one mongo container is working meanwhile the other is shutting down because it said
DBPathInUse: Unable to lock the lock file: /data/db/mongod.lock (Unknown error). Another mongod instance is already running on the /data/db directory, terminating
This is my docker compose file
version: '3'
services:
frontend:
image: fernandomaxwell/frontend
ports:
- "3007:3007"
networks:
main:
database_frontend:
backend:
image: fernandomaxwell/backend
ports:
- "2007:2007"
networks:
main:
database_backend:
mongo_backend:
image: mongo
volumes:
- "/var/lib/mongodb:/data/db"
ports:
- "27017:27017"
networks:
database_backend:
mongo_frontend:
image: mongo
volumes:
- "/var/lib/mongodb:/data/db"
ports:
- "27018:27017"
networks:
database_frontend:
networks:
main:
database_backend:
database_frontend:
Any idea to solve this?