How do I get Consul to work so I can get Docker overlay to work?

I am running CentOS 7 with Docker. I am trying to install Consul on the Docker server. Consul is unzipped. The binary file works for showing the version. I ran this:

echo $CONSUL_RPC_ADDR

This returns a blank line. I then ran this:

consul join x.x.x.x #where x.x.x.x is the IP address of the server

I get this:

Error connecting to Consul agent: dial tcp 127.0.0.1:8400: getsockopt: connection refused

I then ran this:

consul info

I saw this as the result:

Error connecting to Consul agent: dial tcp 127.0.0.1:8400: getsockopt: connection refused

I checked, port 8400 is not blocked. What should I do to get Consul to work? I want to get Docker overlay to work.

Where are you running this consul join command? in a container or on the host? Where is the consul service you are trying to connect to running on? in a container or on the host?

Each container gets its own 127.0.0.1, so I suspect you may be trying to connect to the wrong one.