Hi,
I’m using https://hub.docker.com/r/bitnami/mongodb/ image with replica set with the following docker composer file:
version: '3'
services:
mongodb-primary:
image: 'bitnami/mongodb:latest'
environment:
- MONGODB_REPLICA_SET_MODE=primary
- MONGODB_ROOT_PASSWORD=password123
- MONGODB_REPLICA_SET_KEY=replicasetkey123
volumes:
- 'mongodb_master_data:/bitnami'
ports:
- 27017:27017
mongodb-secondary:
image: 'bitnami/mongodb:latest'
depends_on:
- mongodb-primary
environment:
- MONGODB_REPLICA_SET_MODE=secondary
- MONGODB_PRIMARY_HOST=mongodb-primary
- MONGODB_PRIMARY_PORT_NUMBER=27017
- MONGODB_PRIMARY_ROOT_PASSWORD=password123
- MONGODB_REPLICA_SET_KEY=replicasetkey123
mongodb-arbiter:
image: 'bitnami/mongodb:latest'
depends_on:
- mongodb-primary
environment:
- MONGODB_REPLICA_SET_MODE=arbiter
- MONGODB_PRIMARY_HOST=mongodb-primary
- MONGODB_PRIMARY_PORT_NUMBER=27017
- MONGODB_PRIMARY_ROOT_PASSWORD=password123
- MONGODB_REPLICA_SET_KEY=replicasetkey123
volumes:
mongodb_master_data:
driver: local
networks:
default:
external:
name: mongo_network
If I deploy this with docker-compose I can connect from the host to ‘mongodb-primary’ without any problem but if I use docker stack deploy I cannot connect to it.
I can see on the stack that the service ‘mongodb-primary’ has the published port
ID NAME MODE REPLICAS IMAGE PORTS
tvvgnc6ubkas mongodb-arbiter replicated 1/1 bitnami/mongodb:latest
0nm7wm1f6xyf mongodb-primary replicated 1/1 bitnami/mongodb:latest *:27017->27017/tcp
glvjo0h6yiki mongodb-secondary replicated 1/1 bitnami/mongodb:latest
but I can’t I connect to it.
With RoboMongo I get the error “Network Unreachable” with the mongo shell (mongo -u root -p password123 --host mongodb://127.0.0.1:27017) the connect just hangs.
Note: I can connect from other container on the same network without any problem.
Update: I’ve tried also to add a port in ‘host’ mode, but the problem is the same.
Can anyone help me?
I’ve
Thanks.
Best regards,
Hugo