dhrm
dhrm

Reputation: 14944

Docker compose access to port on host

I'm running another docker-compose exposing Logstash on port 5044 (using docker-elk). I'm able to make requests to the service on localhost:5044 on my host, so the port is exposed correctly.

I'm then running another docker-compose (Filebeat) but from there I cannot connect to "localhost:5044". Here is the docker compose file:

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?

Upvotes: 2

Views: 10992

Answers (1)

omu_negru
omu_negru

Reputation: 4770

First of all, the compose file you linked exposes port 5000, but you say you're trying to connect to port 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.

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.x.x

  • Connect both services to an external created network like so:

    • first create the network with 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

Good luck

Upvotes: 4

Related Questions