简体   繁体   English

Docker组成对主机端口的访问

[英]Docker compose access to port on host

I'm running another docker-compose exposing Logstash on port 5044 (using docker-elk ). 我正在运行另一个docker-compose在端口5044上暴露Logstash(使用docker -elk )。 I'm able to make requests to the service on localhost:5044 on my host, so the port is exposed correctly. 我可以在主机上的localhost:5044上向服务发出请求,因此端口可以正确公开。

I'm then running another docker-compose (Filebeat) but from there I cannot connect to "localhost:5044". 然后,我正在运行另一个docker-compose(Filebeat),但是从那里我无法连接到“ localhost:5044”。 Here is the docker compose file: 这是docker compose文件:

version: '2'

services:

  filebeat:
    build: filebeat/
    networks:
      - elk

networks:

  elk:
    driver: bridge

Any cluye why the localhost:5044 is not accessable in this docker compose? 知道为什么在此docker compose中无法访问localhost:5044吗?

First of all, the compose file you linked exposes port 5000, but you say you're trying to connect to port 5044. 首先,您链接的撰写文件公开了端口5000,但是您说您正在尝试连接到端口5044。

Secondly, exposing port 5044 (or 5000) will make the port available to the host machine, not to other containers launched with other compose files. 其次,公开端口5044(或5000)将使该端口可用于主机,而不可用于使用其他撰写文件启动的其他容器。

The way i see it is you can either: 我的看法是,您可以:

  • keep the first service as it is and instead of localhost:port on the secon service use your_ip:port , where your_ip can be retrieved from ifconfig -a or something similar and should look like 192.168.xx 保持第一个服务不变,而不是secon服务上的localhost:port,请使用your_ip:port,其中your_ip可以从ifconfig -a或类似的文件中检索到,并且应类似于192.168.xx

  • Connect both services to an external created network like so: 将两个服务都连接到外部创建的网络,如下所示:

    • first create the network with docker network create foo 首先使用docker network create foo创建网络
    • link the services to the external network in the compose file: 在撰写文件中将服务链接到外部网络:

networks: test_network: external: true

Then access change the logstash reference from localhost:port to logstash:port 然后访问,将logstash参考从localhost:port更改为logstash:port

Good luck 祝好运

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM