Docker Community Forums

Share and learn in the Docker community.

Docker-compose networks and network_mode

(Yaofei) #1

I have the below scenario and love to know any solution using docker-compose, and not in swarm mode yet.

I want to svc1 and svc2 be able to talk with each other through bridge network, and also using host network. I know you cannot have both networks and network_mode in docker-compose.

The use case is Kibana needs to talk with Elasticsearch, on the same host. Or, can I have Kibaba bind to an IP on host and Elasticsearch bind to another IP on the host. Can I accomplish it. Or, what’s the best way to address it.


(David Maze) #2

You can do this with the standard networking setup. Docker Compose will create a network for you. Docker then provides an internal DNS service to your containers. If you have a single container labeled as elasticsearch: in the docker-compose.yml file, then Kibana can connect to http://elasticsearch:9200/. On the flip side, whatever you specify under ports: will be visible from the outside, so you can publish Kibana, and if you’d like also publish Elasticsearch.

(Yaofei) #3

Thanks David,
Are you saying I don’t need to use “network_mode: host”, instead using default_bridge network and “ports” to expose to the VM’s IP?


(David Maze) #4

All of that is correct. You don’t need any non-default network settings at all.

(Yaofei) #5

Thanks David,
But here I got error for binding without using “network_mode: host”.

In elasticsearch.yml, I use VM’s private IP

#--- Network ---

In docker-compose.yml

  - '9200:9200'
  - '9300:9300'

I got the following error from Elasticsearch:

elasticsearch    | [2018-03-02T20:00:23,178][WARN ][o.e.b.ElasticsearchUncaughtExceptionHandler] [node-1] uncaught exception in thread [main]
elasticsearch    | org.elasticsearch.bootstrap.StartupException: BindTransportException[Failed to bind to [9300-9400]]; nested: BindException[Cannot assign requested address];

If I change elasticsearch.yml to the following, it will work fine but I cannot reach it from the VM’s public IP.
  - _local_

Please help.

(David Maze) #6

Set it to (probably) _site_ (or if not that, _global_).

You will have trouble accessing the ES server directly from outside the current physical host; most clients have an option to ignore the set of servers ES returns in its initial bootstrap. Clustering ES here is also a little tricky. But for a single node this recipe should work.