Prisma Mongodb & Express Res API Docker
Hi I am tryin to create a docker compose that ecompasses A Rest API in Prisma and Express.js and a MongoDB Database. I am using this docker-compose file:
name: 'proofifi-project'
services:
mongo:
# This image automatically creates a replica set required for transactions
image: prismagraphql/mongo-single-replica:4.4.3-bionic
environment:
MONGO_INITDB_ROOT_USERNAME: root
MONGO_INITDB_ROOT_PASSWORD: prisma
MONGO_INITDB_DATABASE: proofifi
MONGO_REPLICA_HOST: host.docker.internal
MONGO_REPLICA_PORT: 27017
INIT_WAIT_SEC: 3
ports:
- 27017:27017
hostname: mongo
container_name: mongo
networks:
- proofifi-network
backend:
build:
context: ../../backend
dockerfile: Dockerfile
ports:
- 3001:3001
environment:
- DATABASE_URL=mongodb://root:prisma@localhost:27017/proofifi?authSource=admin&retryWrites=false
depends_on:
- mongo
hostname: backend
container_name: backend
networks:
- proofifi-network
volumes:
mongo-data:
networks:
proofifi-network:
driver: bridge
But I get always the same error:
Message:
Kind: Server selection timeout: No available servers. Topology: { Type: Unknown, Servers: [ { Address: localhost:27017, Type: Unknown, Error: Kind: I/O error: Connection refused (os error 111), labels: {} } ] }, labels: {}
Do you guys know if there is a docker compose that encompasses a prisma rest api and mongodb?4 Replies
Hello 👋
Once you start your docker container, are you able to connect to the running mongodb instance using a GUI tool like MongoDB Compass?
Here are our internal Docker Compose file we use for testing:
https://github.com/prisma/prisma/blob/main/docker/docker-compose.yml#L178
https://github.com/prisma/prisma/blob/main/docker/mongodb_replica/Dockerfile
This could be helpful to you
GitHub
prisma/docker/mongodb_replica/Dockerfile at main · prisma/prisma
Next-generation ORM for Node.js & TypeScript | PostgreSQL, MySQL, MariaDB, SQL Server, SQLite, MongoDB and CockroachDB - prisma/prisma
Hi Nurul,
thank you for your quick reply! I successfully managed to run this docker-compose:
https://github.com/prisma/prisma-examples/blob/latest/databases/mongodb/docker-compose.yml
And the REST API worked perfectly when I made it start from the terminal as a node application.
I was thinking to create a docker-compose that would encompass the mongodb plus the REST API to use in production but since you are talking about testing maybe the best thing to do is to just create a docker compose with the REST API only and then connect this docker image to a mongo DB hosted on Atlas. What do you think?
GitHub
prisma-examples/databases/mongodb/docker-compose.yml at latest · pr...
🚀 Ready-to-run Prisma example projects. Contribute to prisma/prisma-examples development by creating an account on GitHub.
I am glad to hear that the docker compose from prisma-examples repo worked for you!
I would suggest separating your database instance and REST API in different docker containers. This would ensure that both services are unaffected by each other.