Comments (6)
Connecting to the replicaset works from within the network. It seems to be an issue when connecting from outside.
from mongo.
There are a few ways you could get around this problem.
- Implement a reverse proxy using nginx or similar.
- Add explicit ip addresses, change the ports mapping in the container and add the hosts to your hostfile,.
from mongo.
The following worked for me
compose
version: "3.0" # Update the version to "3.0" as per your requirement
volumes:
db-mongo-keys26:
db-mongo-data-26:
db-mongo-data-27:
db-mongo-data-28:
networks:
db-cluster26:
driver: bridge
ipam:
driver: default
config:
- subnet: 162.10.21.0/24
services:
db-mongo-keys26:
image: depop/openssl-bats
volumes:
- db-mongo-keys26:/mongo-conf
command: 'bash -c "openssl rand -base64 741 > /mongo-conf/mongodb-keyfile; chmod 600 /mongo-conf/mongodb-keyfile; chown 999 /mongo-conf/mongodb-keyfile"'
# Node1
db-mongo-node17:
container_name: db-mongo-node17
image: mongo:5.0.24 # Update the MongoDB version to "5.0.24"
volumes:
- db-mongo-keys26:/opt/keyfile
- db-mongo-data-26:/data/db
env_file:
./mongod.env
ports:
- 27017:27017 # Change the host port to 27017
command: 'mongod --auth --keyFile /opt/keyfile/mongodb-keyfile --replSet db-ppd'
depends_on:
- db-mongo-keys26
# Node2
db-mongo-node18:
container_name: db-mongo-node18
image: mongo:5.0.24
volumes:
- db-mongo-keys26:/opt/keyfile
- db-mongo-data-27:/data/db
env_file:
./mongod.env
ports:
- 27018:27018 # Change the host port to 27018
command: 'mongod --port 27018 --auth --keyFile /opt/keyfile/mongodb-keyfile --replSet db-ppd'
depends_on:
- db-mongo-keys26
# Node3
db-mongo-node19:
container_name: db-mongo-node19
image: mongo:5.0.24
volumes:
- db-mongo-keys26:/opt/keyfile
- db-mongo-data-28:/data/db
env_file:
./mongod.env
ports:
- 27019:27019 # Change the host port to 27019
command: 'mongod --port 27019 --auth --keyFile /opt/keyfile/mongodb-keyfile --replSet db-ppd'
depends_on:
- db-mongo-keys26
Command:
rs.initiate({
_id: "db-ppd",
members: [
{_id: 0, host: "db-mongo-node17:27017"},
{_id: 1, host: "db-mongo-node18:27018"},
{_id: 2, host: "db-mongo-node19:27019"}
]
})
Host file on host
127.0.0.1 db-mongo-node17
127.0.0.1 db-mongo-node18
127.0.0.1 db-mongo-node19
Connection string:
mongodb://root:example@db-mongo-node17:27017,db-mongo-node18:27018,db-mongo-node19:27019/?replicaSet=db-ppd
from mongo.
@LaurentGoderre are you working on your local system or some clous because the same thing i am trying on my aws ec2, it is giving error WARNING: Some networks were defined but are not used by any service: db-cluster26
Creating network "ec2-user_default" with the default driver
Creating volume "ec2-user_db-mongo-keys26" with default driver
Creating volume "ec2-user_db-mongo-data-26" with default driver
Creating volume "ec2-user_db-mongo-data-27" with default driver
Creating volume "ec2-user_db-mongo-data-28" with default driver
Creating ec2-user_db-mongo-keys26_1 ... done
Creating db-mongo-node19 ...
Creating db-mongo-node17 ... error
Creating db-mongo-node18 ...
Creating db-mongo-node19 ... done
de17 (07973999b06c76bc04444a43530a0aff03a9dbc623e9ac18dd2019e7f5748f63): Error starting userland proxy: listen tcp4 0.0.0.0:27017: bind: Creating db-mongo-node18 ... done
ERROR: for db-mongo-node17 Cannot start service db-mongo-node17: driver failed programming external connectivity on endpoint db-mongo-node17 (07973999b06c76bc04444a43530a0aff03a9dbc623e9ac18dd2019e7f5748f63): Error starting userland proxy: listen tcp4 0.0.0.0:27017: bind: address already in use
ERROR: Encountered errors while bringing up the project.
[ec2-user@ip-12-1-27-125 ~]$ docker exec -it db-mongo-node18 bash
root@5252644ac2d7:/# mongo
MongoDB shell version v5.0.24
connecting to: mongodb://127.0.0.1:27017/?compressors=disabled&gssapiServiceName=mongodb
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 refused :
connect@src/mongo/shell/mongo.js:372:17
@(connect):2:6
exception: connect failed
from mongo.
If you have any reference to install it with full setup with docker-compose or something, It will be very helpful on Amazon linux2, 5.0.24
from mongo.
This was on a local setup. Maybe you can use all non-default ports to avoid port in use error (27018, 27019, 27020)
from mongo.
Related Issues (20)
- docker run mongo failed
- Mongo 6.0+ Fails to Run Using WSL HOT 6
- Is it possible Docker without WSL?
- Need help with CVE-2023-24538, CVE-2023-24540, CVE-2024-21626 and CVE-2023-27561 HOT 4
- Mongo container sends network requests to mysterious EC2 servers at AWS HOT 9
- MongoDB container not always initialising after clearing volumes HOT 1
- 7.0.7 tag is missing linux/arm64 image HOT 1
- mongod:6.0.13 - Failed during mongod binary build in docker image.
- docker PIDS keeps increasing at 7.0.8 HOT 1
- Can't connect apps to MongoDB inside docker in Linux HOT 2
- `ENTRYPOINT` documentation HOT 1
- The docker container is throwing connection error if host machine is also running a mongodb on port 27017.
- Docker encountered an exited while in use
- mongo in the container does not properly listen on IPv6
- custom mongod.conf file append to docker mongo it restarts HOT 1
- Operation not permitted\nActual exception type: std::system_error HOT 1
- security issues with stdlib HOT 2
- Is this a vulnerability? Under the set credentials, the client does not have credentials to connect but cannot operate HOT 1
- Why add originalArgOne=mongod to environment variables HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from mongo.