我有一个应用程序,运行在docker,它是mongodb和我建立从我的docker组成,但我只能在docker内运行它,不能从我的本地主机运行,这是我的docker组成。
version: "3.7"
services:
mongodb01:
image: "bitnami/mongodb:4.2"
hostname: mongodb01.dev.com
ports:
- 27017:27017
restart: always
environment:
- MONGODB_ADVERTISED_HOSTNAME=mongodb01.dev.com
- MONGODB_REPLICA_SET_MODE=primary
- MONGODB_REPLICA_SET_NAME=rs0
- MONGODB_ROOT_PASSWORD=password123
- MONGODB_REPLICA_SET_KEY=replicasetkey123
- MONGODB_ENABLE_DIRECTORY_PER_DB=yes
volumes:
- "mongodb01_data:/bitnami/mongodb"
networks:
mongodb:
aliases:
- mongodb01.dev.com
mongodb02:
image: "bitnami/mongodb:4.2"
hostname: mongodb02.dev.com
ports:
- 27018:27018
restart: always
depends_on:
- mongodb01
environment:
- MONGODB_ADVERTISED_HOSTNAME=mongodb02.dev.com
- MONGODB_REPLICA_SET_MODE=secondary
- MONGODB_REPLICA_SET_NAME=rs0
- MONGODB_PRIMARY_HOST=mongodb01.dev.com
- MONGODB_PRIMARY_ROOT_PASSWORD=password123
- MONGODB_REPLICA_SET_KEY=replicasetkey123
- MONGODB_ENABLE_DIRECTORY_PER_DB=yes
- MONGODB_PORT_NUMBER=27018
volumes:
- "mongodb02_data:/bitnami/mongodb"
networks:
mongodb:
aliases:
- mongodb02.dev.com
mongodb03:
image: "bitnami/mongodb:4.2"
hostname: mongodb03.dev.com
ports:
- 27019:27019
restart: always
depends_on:
- mongodb02
environment:
- MONGODB_ADVERTISED_HOSTNAME=mongodb03.dev.com
- MONGODB_REPLICA_SET_MODE=secondary
- MONGODB_REPLICA_SET_NAME=rs0
- MONGODB_PRIMARY_HOST=mongodb01.dev.com
- MONGODB_PRIMARY_ROOT_PASSWORD=password123
- MONGODB_REPLICA_SET_KEY=replicasetkey123
- MONGODB_ENABLE_DIRECTORY_PER_DB=yes
- MONGODB_PORT_NUMBER-27019
volumes:
- "mongodb03_data:/bitnami/mongodb"
networks:
mongodb:
aliases:
- mongodb03.dev.com
volumes:
mongodb01_data:
mongodb02_data:
mongodb03_data:
networks:
mongodb:
我试图建立mongodb replicaset,但我喜欢从我的localhost mongo运行它,它如何能使可能吗?
要想在本地主机上运行它,你需要暴露端口。ports:
- 27017:27017
到你的服务。看看这个 岗位