[英]Cannot connect to mongo docker from another docker
After looking this and this and this post, I couldn't connect to mongo from another docker.看了这个、 这个和这个帖子后,我无法从另一个 docker 连接到 mongo。 This is a part of my DockerFile:
这是我的 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"]
In my telegram service I am connecting to mongo like this:在我的电报服务中,我像这样连接到 mongo:
register_connection(
alias='main',
name='new_tetabot',
host='mongo',
port=27017
)
And this is my docker-compose.yml file:这是我的 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"
When I use docker-compose up
I get Failed to connect to mongo port 27017: Connection refused
.当我使用
docker-compose up
我得到Failed to connect to mongo port 27017: Connection refused
。 But I have telnet from localhost (outside of docker) to 127.0.0.1
on port 27017
.但是我有从 localhost(docker 之外)到
127.0.0.1
端口27017
。 My docker-compose version is docker-compose version 1.23.2, build 1110ad01
and when I run docker-compose up
the result of docker ps
is我的
docker-compose version 1.23.2, build 1110ad01
-compose 版本是docker-compose version 1.23.2, build 1110ad01
并且当我运行docker-compose version 1.23.2, build 1110ad01
docker-compose up
时docker-compose version 1.23.2, build 1110ad01
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
You need to remove extra_hosts
from your docker-compose.yml
when using links
.使用
links
时,您需要从extra_hosts
docker-compose.yml
删除extra_hosts
。 The telegram container is unable to resolve the correct address for mongo
because it was overrided to 127.0.0.1
.电报容器无法解析
mongo
的正确地址,因为它已被覆盖为127.0.0.1
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.