ERROR: http://rancher:8080/v1 is not accessible

I am trying to run rancher to test it out and promote it with in my organization.
Here i have a multivm vagrant based setup. All the VMs are CentOS 7 (Linux host1 3.10.0-327.el7.x86_64 #1MP Thu Nov 19 22:10:57 UTC 2015 x86_64 x86_64 x86_64 GNU/Linux)

  1. One machine is dedicated to rancher.
  2. Two other machines are host1 and host2.
    Note: all these machines can ping each other and do ssh.
    I ran rancher in my rancher server box with following command:
    $ sudo docker run -d --restart=unless-stopped -p 8080:8080 rancher/server:stable
    This works fine i can see the UI and then when i try to add the host using this command

sudo docker run --rm --privileged -v /var/run/docker.sock:/var/run/docker.sock -v /var/lib/rancher:/var/lib/rancher rancher/agent:v1.2.2 http://rancher:8080/v1cripts/78651D3B0D78F77EF0B9:1483142400000:dIEJCGrcGbIKE0jHF7C3oU7bwOY
I see following output,
INFO: Running Agent Registration Process, CATTLE_URL=http://rancher:8080/v1
INFO: Attempting to connect to: http://rancher:8080/v1
ERROR: http://rancher:8080/v1 is not accessible
ERROR: http://rancher:8080/v1 is not accessible
If i do curl i get following outputs,
[vagrant@host1 ~]$ curl -k -i http://rancher:8080/v1
HTTP/1.1 401 Unauthorized
Content-Type: application/json; charset=utf-8
Date: Wed, 24 May 2017 15:33:28 GMT
Expires: Thu, 01 Jan 1970 00:00:00 GMT
Server: Jetty(9.2.11.v20150529)
Set-Cookie: PL=rancher;Path=/
Www-Authenticate: Basic realm="Enter API access key and secret key as username and password"
X-Api-Schemas: http://rancher:8080/v1/schemas
X-Rancher-Version: v1.5.10
Content-Length: 177
{“id”:“ecd5644f-e765-4dc3-bc77-e9d7a2797184”,“type”:“error”,“links”:{},“actions”:{},“status”:401,“code”:“Uuthorized”,“message”:“Unauthorized”,“detail”:null,“baseType”:“error”}
[vagrant@host1 ~]$ curl -k -i http://rancher:8080/v1cripts/78651D3B0D78F77EF0B9:1483142400000:dIEJCGrcGbIKE0jHF7C3oU7bwOY
HTTP/1.1 200 OK
Content-Type: text/plain
Date: Wed, 24 May 2017 15:34:04 GMT
Expires: Thu, 01 Jan 1970 00:00:00 GMT
Server: Jetty(9.2.11.v20150529)
Set-Cookie: PL=rancher;Path=/
Vary: Accept-Encoding, User-Agent
Www-Authenticate: Basic realm="Enter API access key and secret key as username and password"
X-Api-Schemas: http://rancher:8080/v1/schemas
X-Rancher-Version: v1.5.10
Content-Length: 263
#!/bin/sh
export CATTLE_REGISTRATION_ACCESS_KEY="registrationToken"
export CATTLE_REGISTRATION_SECRET_KEY="78651D3B0D78F77EF0B9:1483142400000:dIEJCGrcGbIKE0jHF7C3oU7bwOY"
export CATTLE_URL="http://rancher:8080/v1"
export DETECTED_CATTLE_AGENT_IP=“192.168.33.21”

Not sure how to proceed from here. And do further debugging.

Only thing I can think of here is that rancher in your example is resolvable from the host but not within the container. Remember that the agent runs in a container which doesn’t have any /etc/hosts modifications that the host may have. Can you let me know if this helps?