Docker image for elastic search

While creating a docker image for ES I downloaded 2.3.4 ES and changed my config file as below

cluster.name: my-application node.name: ravi-1 node.master: true node.data: true network.host: 172.16.1.92 http.port: 9200 discovery.zen.ping.multicast.enabled: false

and while bringing up its showing an error of

[2016-07-28 10:23:16,164][INFO ][node ] [ravi-1] starting ... Exception in thread "main" BindTransportException[Failed to bind to [9300-9400]]; nested: ChannelException[Failed to bind to: /172.16.1.92:9400]; nested: BindException[Cannot assign requested address]; Likely root cause: java.net.BindException: Cannot assign requested address at sun.nio.ch.Net.bind0(Native Method) at sun.nio.ch.Net.bind(Net.java:433) at sun.nio.ch.Net.bind(Net.java:425) at sun.nio.ch.ServerSocketChannelImpl.bind(ServerSocketChannelImpl.java:223) at sun.nio.ch.ServerSocketAdaptor.bind(ServerSocketAdaptor.java:74) at org.jboss.netty.channel.socket.nio.NioServerBoss$RegisterTask.run(NioServerBoss.java:193) at org.jboss.netty.channel.socket.nio.AbstractNioSelector.processTaskQueue(AbstractNioSelector.java:391) at org.jboss.netty.channel.socket.nio.AbstractNioSelector.run(AbstractNioSelector.java:315) at org.jboss.netty.channel.socket.nio.NioServerBoss.run(NioServerBoss.java:42) at org.jboss.netty.util.ThreadRenamingRunnable.run(ThreadRenamingRunnable.java:108) at org.jboss.netty.util.internal.DeadLockProofWorker$1.run(DeadLockProofWorker.java:42) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) at java.lang.Thread.run(Thread.java:745)

And if I remove the config file and run with elasticsearch --networkhost _non_loopback__ is working fine. But why that error is coming for my config???
Is it ok to work with _non_loopback_ to maintain a 4 node cluster???

Using configurations like network.host: 172.16.1.92 is bogus. Docker containers pick IPs from a range, so how you do know this is always the correct IP? One answer would be address wildcarding. Elasticsearch does not offer address wildcarding e.g. network.bind_host: * so you must use something like network.bind_host: 0.0.0.0 or network.bind_host: 0 for this, but where behavior details (IPv4, IPv6 support) depend on the JVM implementation.

Thanks for your answer. I found out a way for taking our ip in the docker.

When I start the ES in the docker image with some flags --net=host its showing

[2016-08-01 10:54:12,454][INFO ][transport ] [ravi-1] publish_address {172.16.1.92:9300}, bound_addresses {172.16.1.92:9300}
[2016-08-01 10:54:15,572][INFO ][http ] [ravi-1] publish_address {172.16.1.92:9200}, bound_addresses {172.16.1.92:9200}

Now its taking the IP as I mentioned. But is this the correct way to mention IP or any other better ways. I want to maintain cluster a cluster of 4 nodes. Please suggest a best method to mention IP in the docker image

Is it ok to work with _non_loopback_ to maintain a 4 node cluster???

I don't see why it would be a problem.

I think you mean --network.host=`hostname` because --net=host does not work here.

In the case of using hostname, you depend on the Docker container /etc/hostname setting up a working network, i.e. copying the /etc/hosts from the Docker daemon host and a working /etc/resolv.conf. Fortunately Docker is doing this behind the scenes at start of a container, e.g. pre-populating DNS resolver with Google's DNS resolver. But that can be overridden by anyone who starts a container.

On the other hand, binding to wildcard interface 0.0.0.0 does not depend on any Docker network setup, it "just works"(tm).