简体   繁体   English

docker撰写网络版本3 –除非使用公共IP,否则容器无法互相看到?

[英]docker compose network version 3 – containers can't see each other unless using public IP?

I have an app running that uses influxdb, chronograf (a webUI admin interface for influx), and grafana (a graph UI interface for influx). 我运行的应用程序使用influxdb,chronograf(用于influx的webUI管理界面)和grafana(用于influx的图形UI界面)。

My docker-compose fill brings up all 3 as services and uses version 3: 我的docker-compose fill将所有这3种服务作为服务并使用了版本3:

version: '3'

services:
    grafana:
        image: grafana/grafana
        container_name: "grafana"
        volumes:
          - ${GRAFANA_DATA_PATH}:/var/lib/grafana
        ports:
          - "3000:3000"
        networks:
          - influxdb

    influxdb:
        image: influxdb:1.4.3-alpine
        container_name: "influxdb"
        volumes:
          - ${INFLUXDB_DATA_PATH}:/var/lib/influxdb
        ports:
          - "8086:8086"
        networks:
          - influxdb

    chronograf:
        image: chronograf:1.4.0-alpine
        container_name: "chronograf"
        volumes:
          - ${CHRONOGRAF_DATA_PATH}:/var/lib/chronograf
        ports:
          - "8888:8888"
        networks:
          - influxdb
        entrypoint:
          - chronograf
          - --influxdb-url=http://influxdb:8086

networks:
     influxdb:

Everything seems to work ok except that when I log into grafana (on port 3000), and go to connect a data source (influxdb running on 8086), it will not work unless I use the server's public IP address. 一切似乎都正常,除了当我登录grafana(在端口3000上)并连接数据源(运行在8086上的influxdb)时,除非我使用服务器的公共IP地址,否则它将无法正常工作。

None of these work: 这些都不起作用:

- "http://localhost:8086"
- "http://127.0.0.1:8086"
- "http://influxdb:8086"

However this works: 但这有效:

- "http://4.25.24.11:8086"

This is a problem because I don't want to expose port 8086 public - it just needs to be accessible by the other containers. 这是一个问题,因为我不想公开公开8086端口-只需其他容器即可访问它。 This used to be accomplished using "links" but that is deprecated and I'm trying to figure out how to do it in docker version 3. 过去使用“链接”可以完成此操作,但已弃用,我正在尝试弄清楚如何在Docker版本3中执行此操作。

Interestingly, chronograf has no problem connecting to influxdb when it starts up (as you can see in the entry point): 有趣的是,chronograf在启动时连接到influxdb时没有问题(如您在入口点中看到的):

--influxdb-url=http://influxdb:8086

Figured it out about 5 minutes after posting the question (It's specific to Grafana): change the "access" field in HTTP settings to "proxy" (instead of "direct"). 在发布问题(大约是Grafana的问题)大约5分钟后就解决了:将HTTP设置中的“访问”字段更改为“代理”(而不是“直接”)。

Hopefully this might save someone some time: 希望这可以节省一些时间:

在此处输入图片说明

If using docker's net: "host" (or docker compose 3, network_mode: "host"), you can use the direct setting because the container is sharing the network with the host. 如果使用docker的网络:“主机”(或docker组成3,network_mode:“主机”),则可以使用直接设置,因为容器正在与主机共享网络。

However if using a named network (such as in the compose file above), you may need to use proxy any time you use the network name in a URL string. 但是,如果使用命名网络(例如上面的撰写文件中的网络),则在URL字符串中使用网络名称时,可能需要使用代理。

i think you are wrong, from chronograf you can access influxdb with just influxdb because both services are on same network and influxdb is just a DNS record from chronograf. 我认为您错了,从chronograf可以只使用influxdb访问influxdb,因为这两个服务都在同一网络上,而influxdb只是chronograf的DNS记录。 you can try this command to verify if the port is open on that host, if it says open then communication should work 您可以尝试使用此命令来验证该主机上的端口是否打开,如果显示“ open”,则表明通信应该正常

docker-compose run chronograf nc influxdb 8086 -v

i would also add depends_on to your docker-compose.yml and the influxdb port doesnt have to be exposed to public, i would rather also use command instead of entrypoint 我还将在您的docker-compose.yml中添加depends_on ,并且influxdb端口不必公开,我宁愿也使用command代替entrypoint

version: '3'

services:
    grafana:
        image: grafana/grafana
        depends_on: [influxdb]
        ports:
          - "3000:3000"
        networks:
          - influxdb

    influxdb:
        image: influxdb:1.4.3-alpine
        networks:
          - influxdb

    chronograf:
        image: chronograf:1.4.0-alpine
        depends_on: [influxdb]
        ports:
          - "8888:8888"
        networks:
          - influxdb
        command:
          - chronograf
          - --influxdb-url=http://influxdb:8086

networks:
    influxdb:

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 为什么docker容器不能在一个网络内通过ip互相访问? - Why docker containers can't access each other by ip within one network? 连接到同一网络但不能通过名称相互引用的两个 docker 容器,只能通过 IP - Two docker containers attached to same network but can't reference each other by name, only IP 码头工人组成 | 为什么容器不能互相到达? - Docker-Compose | why the containers can't reach each other? Docker 容器在 docker compose 中无法看到彼此,主机也无法看到 - Docker containers are not able to see each other in docker compose, nor is host 使用docker-compose将docker容器相互链接时如何处理IP地址? - How to handle IP addresses when linking docker containers with each other using docker-compose? docker 同一网络上的容器(来自撰写)看不到对方 - docker containers on the same net (from compose) don't see each other Docker 容器(MariaDb、AspNet)无法在 Compose 网络上通信 - Docker Containers (MariaDb, AspNet) Can't Communicate on Compose Network Docker compose无法访问其他容器的端口 - Docker compose can't access ports of other containers Docker Compose-Network_mode:Service:-2个容器无法互相通信 - Docker Compose - Network_mode:Service: - 2 containers cant talk to each other 无法连接到Docker网络中的其他容器 - Can't connect to other containers inside docker network
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM