无法从另一个泊坞窗连接到mongo泊坞窗

时间:2019-03-11 12:44:37

标签: mongodb docker docker-compose

查看了thisthisthis的帖子后,我无法从另一个码头工人连接到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

0 个答案:

没有答案