You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
While using Docker containers for development, I encountered an issue where Prisma's recommended MongoDB Docker Compose configuration fails to start the replica set.
Error Log:
When running the provided docker-compose.yml, the following error occurs:
mongodb-prisma-transactions-mongodb_container-1 | Waiting for initialization...
mongodb-prisma-transactions-mongodb_container-1 | Initializing replica set...
mongodb-prisma-transactions-mongodb_container-1 | Error: couldn't connect to server 127.0.0.1:27017, connection attempt failed: SocketException: Error connecting to 127.0.0.1:27017 :: caused by :: Connection refusedThe container then exits with code 1.
The container then exits with code 1.
Cause:
The issue occurs because the provided docker-compose.yml file lacks a networks definition. Since Docker does not automatically assign a default network in this scenario, the MongoDB container fails to establish a connection, causing the replica set initialization to fail.
Fix:
To resolve this, I added a networks section to the mongodb_container service and defined a named network.
Here is the corrected docker-compose.yml:
version: "3.7"
name: mongodb-prisma-transactions
services:
mongodb_container:
# 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
INIT_WAIT_SEC: 3
ports:
- 27017:27017
networks:
- my-network
# Define networks
networks:
my-network:
With this fix, the MongoDB container starts successfully, and the replica set initializes without issues.
Would it be possible to update the official Prisma documentation or Docker Compose template to include this fix?
Thanks! 🚀
Additional Reference:
According to Docker’s official networking documentation, services within Docker Compose need to be explicitly networked when running multi-container applications.
Since MongoDB’s replica sets require proper network communication, missing this configuration can cause connection failures. This is also mentioned in MongoDB’s deployment guide.
The text was updated successfully, but these errors were encountered:
Description:
While using Docker containers for development, I encountered an issue where Prisma's recommended MongoDB Docker Compose configuration fails to start the replica set.
Error Log:
When running the provided docker-compose.yml, the following error occurs:
The container then exits with code 1.
Cause:
The issue occurs because the provided docker-compose.yml file lacks a networks definition. Since Docker does not automatically assign a default network in this scenario, the MongoDB container fails to establish a connection, causing the replica set initialization to fail.
Fix:
To resolve this, I added a networks section to the mongodb_container service and defined a named network.
Here is the corrected docker-compose.yml:
With this fix, the MongoDB container starts successfully, and the replica set initializes without issues.
Would it be possible to update the official Prisma documentation or Docker Compose template to include this fix?
Thanks! 🚀
Additional Reference:
According to Docker’s official networking documentation, services within Docker Compose need to be explicitly networked when running multi-container applications.
Since MongoDB’s replica sets require proper network communication, missing this configuration can cause connection failures. This is also mentioned in MongoDB’s deployment guide.
The text was updated successfully, but these errors were encountered: