查看了this和this和this的帖子后,我无法从另一个码头工人连接到mongo。 这是我的DockerFile的一部分:
FROM ubuntu:16.04
...
WORKDIR /code
# Install project requirements
RUN pip3 install -r requirements.pip
ADD . /code
ENTRYPOINT ["/usr/bin/supervisord", "-c", "/code/supervisord.conf"]
在电报服务中,我这样连接到mongo:
register_connection(
alias='main',
name='new_tetabot',
host='mongo',
port=27017
)
这是我的docker-compose.yml文件:
version: '3'
services:
telegram:
hostname: nh-11
build: .
ports:
- "9001:9001"
- "5555:5555"
extra_hosts:
postgresql: 127.0.0.1
mongo: 127.0.0.1
redis: 127.0.0.1
es: 127.0.0.1
broker: 127.0.0.1
volumes:
- /root/telegram_logs:/root/telegram_logs
- /home/crawler/telegram/sessions:/root/crawler/telegram/sessions
- /root/downloads:/root/downloads
- /root/images:/root/images
restart:
always
depends_on:
- mongo
- redis
links:
- mongo
- redis
redis:
image: "redis:latest"
ports:
- "6379:6379"
expose:
- "6379"
mongo:
image: "mongo:4"
ports:
- "27017:27017"
expose:
- "27017"
使用docker-compose up
时得到Failed to connect to mongo port 27017: Connection refused
。但是我有从本地主机(码头工人外部)到127.0.0.1
端口27017
上的telnet。
我的docker-compose版本是docker-compose version 1.23.2, build 1110ad01
,当我运行docker-compose up
时,docker ps
的结果是
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
dfa23e7d07dd telegram_telegram "/bin/sh -c 'curl \"m…" 2 minutes ago Restarting (7) 11 seconds ago telegram_telegram_1
74d875f3828c mongo:4 "docker-entrypoint.s…" 2 minutes ago Up 2 minutes 0.0.0.0:27017->27017/tcp telegram_mongo_1
6ee448c1cc30 redis:latest "docker-entrypoint.s…" 2 minutes ago Up 2 minutes 0.0.0.0:6379->6379/tcp telegram_redis_1