这是我的yml:
mongodb:
image: mongo:latest
environment:
MONGO_INITDB_ROOT_USERNAME: root
MONGO_INITDB_ROOT_PASSWORD: example
ports:
- "27017:27017"
healthcheck:
test: ["CMD", "mongo", "--eval", "db.adminCommand('ping')"]
interval: 10s
retries: 5
start_period: 5s
restart: always
volumes:
- mongodb-data:/data/db
容器中的mongosh:
admin> show dbs
JobDB 432.00 KiB << this is my testing db, there're some collections and data
admin 100.00 KiB
config 108.00 KiB
local 72.00 KiB
docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
fb43b9cbfb63 apache/airflow:2.7.3 "/usr/bin/dumb-init …" 48 minutes ago Up 48 minutes (healthy) 8080/tcp automation-airflow-triggerer-1
52af82cb0b13 apache/airflow:2.7.3 "/usr/bin/dumb-init …" 48 minutes ago Up 48 minutes (healthy) 0.0.0.0:8080->8080/tcp automation-airflow-webserver-1
28f084bff929 apache/airflow:2.7.3 "/usr/bin/dumb-init …" 48 minutes ago Up 48 minutes (healthy) 8080/tcp automation-airflow-scheduler-1
da474b892d84 apache/airflow:2.7.3 "/usr/bin/dumb-init …" 48 minutes ago Up 48 minutes (healthy) 8080/tcp automation-airflow-worker-1
e27505eb04e9 redis:latest "docker-entrypoint.s…" 48 minutes ago Up 48 minutes (healthy) 6379/tcp automation-redis-1
ee686330e99d mysql:8.0 "docker-entrypoint.s…" 48 minutes ago Up 48 minutes 33060/tcp, 0.0.0.0:3308->3306/tcp automation-mysqldb-1
d8b4971d9b86 postgres:13 "docker-entrypoint.s…" 48 minutes ago Up 48 minutes (healthy) 5432/tcp automation-postgres-1
f4ad04c6de18 mongo:latest "docker-entrypoint.s…" 48 minutes ago Up 48 minutes (unhealthy) 0.0.0.0:27017->27017/tcp automation-mongodb-1
docker网络ls
NETWORK ID NAME DRIVER SCOPE
f45e66a2be2e automation_default bridge local
连接扩展:
docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' automation-mongodb-1
带上这个容器的IP仍然没有与UI连接
您遇到超时错误,因为您尝试使用未知的 URI 连接 MongoDB 服务器。您在 URI 中使用了
mongodb
,这是不正确的。仅当您尝试从同一 MongoDB 容器网络中的其他服务连接服务器时,才应该这样做。
由于您似乎是从主机连接,因此您需要使用此 URI:
mongodb://root:[email protected]:27017
。您可以这样做,因为您在 MongoDB 服务的 docker compose 配置中导出了端口 27017
,因此该端口在您的主机上可用。