Docker组合,单独运行时无法与暴露的端口通信?

时间:2018-05-01 14:52:33

标签: docker docker-compose

我单独运行了两项服务

docker-compose run --service-ports django /bin/bash
docker-compose run --service-ports other /bin/bash

虽然我可以看到docker ps中的端口,但服务无法与其他服务中的公开端口通信。

$ docker ps

CONTAINER ID        IMAGE                            COMMAND                  CREATED             STATUS              PORTS                      NAMES

586e859afcab        littlehome_other                 "/bin/bash"              12 minutes ago      Up 12 minutes       6379-6380/tcp, 9200/tcp    zibann-reservation_other_run_6

994dadb0ad7f        littlehome                       "/bin/bash"              25 minutes ago      Up 25 minutes       0.0.0.0:10011->10011/tcp   zibann-reservation_django_run_3

docker-compose.yml有

 services:
  django:
    restart: always
    build:
      context: .
      dockerfile: ./compose/production/django/Dockerfile
    image: littlehome
    depends_on:
      - other
      - nginx
    env_file:
      - ./compose/.envs/production/postgres
    # command: /app/compose/production/django/uwsgi.sh
    ports:
      - "0.0.0.0:10011:10011"

 other:
    build:
      context: .
      dockerfile: ./compose/production/other/Dockerfile
    image: littlehome_other
    # depends_on:
    #   - postgres
    expose:
      - "9200"
      - "6379"
      - "6380"
    volumes:
      - ~/.bash_history:/root/.bash_history

我想让djangoother:9200

交谈

docker network inspect zibann-reservation_default显示

  "Containers": {
        "994dadb0ad7f59e6a9ecaddfffe46aba98209ff2ae9eb0542f89dee969a85a17": {
            "Name": "zibann-reservation_django_run_3",
            "EndpointID": "02bf3e21aba290b999d26f0e52f2cb6b3aa792a10c86e08065d0b299995480dd",
            "MacAddress": "02:42:ac:12:00:06",
            "IPv4Address": "172.18.0.6/16",
            "IPv6Address": ""
        },
        "ac5b1845f31f23bce0668ee7a427dc21aafbda0494cf67cc764df7b0898f5d23": {
            "Name": "zibann-reservation_other_run_7",
            "EndpointID": "b6cfcbfbf637d6521575c300d74fb483b47d6fa9e173aeb17f9c5bfc12341a37",
            "MacAddress": "02:42:ac:12:00:02",
            "IPv4Address": "172.18.0.2/16",
            "IPv6Address": ""
        },
        "fe83a3addb7365b2439870e887a4eae50477f1c3531c6af60a91a07bb1226922": {
            "Name": "zibann-reservation_postgres_1",
            "EndpointID": "bee7d0fcc80f94303306d849fbb29a3362d1d71ceb7d34773cd82ab08bc80172",
            "MacAddress": "02:42:ac:12:00:03",
            "IPv4Address": "172.18.0.3/16",
            "IPv6Address": ""
        }
    },

该服务是elasticsearch,客户端正试图通过'http://other:9200/reviewmeta_index/_count'连接到elasticsearch,这会有用吗?

1 个答案:

答案 0 :(得分:1)

确保它们连接到同一网络。

使用 docker network ls 检查网络(使用此处的值稍后连接)

检查容器使用的桥接器: docker network inspect bridge

并连接正确的网络: docker network connect default-bridge zibann-reservation_django_run_3 (默认网桥是您要连接的网络。当然可以是任何东西)

可在此处找到更详细的信息:https://docs.docker.com/network/network-tutorial-standalone/#use-the-default-bridge-networkhttps://docs.docker.com/engine/reference/commandline/network_connect/#related-commands