Unable to access admin port on Sync Gateway

(following on from Issue replicating via Sync Gateway (cannot access admin port))

I’m getting curl: (7) Failed to connect to <ip-address> port 4985: Connection refused

I’m using Docker images, docker ps shows the following:

CONTAINER ID        IMAGE                    COMMAND                  CREATED             STATUS              PORTS                                                                                               NAMES
5a1e69b64442        couchbase/sync-gateway   "sync_gateway https:/"   16 hours ago        Up 16 hours>4984-4985/tcp                                                                    tiny_lumiere
adca39eea937        couchbase                "/entrypoint.sh couch"   5 weeks ago         Up 5 weeks>8091-8094/tcp, 11207/tcp, 11211/tcp,>11210/tcp, 18091-18093/tcp   db

Trying from the server, e.g.

curl -H 'Content-Type: application/json' -X POST -d ' {"source": "https://<username>:<password>@<my-account>.cloudant.com/mydb", "target": "mydb"} '

I get curl: (56) Recv failure: Connection reset by peer

I also can’t see the admin page if I navigate to http://<ip-address>:4985/_admin in the browser.

I don’t know if this is related at all, but if I send e.g.


I get

<a href="/mydb/">Moved Permanently</a>.

Could there be something wrong with the way I’ve installed Sync Gateway via Docker?

By default the admin port binds only to the loopback interface so it can be accessed only from the same host SG is running on. That probably explains your first error.

I don’t know why fails, but I’m unclear on the semantics of as opposed to or localhost. I suspect that may connect through a real network interface rather than loopback, which would explain the error.

The Moved Permanently response is expected; it’s simply a 301 redirect to the same URL with a slash at the end, which is the canonical form. (Look at the Location: response header.)

If I change to or localhost I still get the same error message: Recv failure: Connection reset by peer.

I am running curl from the same server that SG (and Couchbase) is running on.

@traun, any ideas? You’re the Docker guru :slight_smile:

Any tips on what else I can try, maybe deleting the Docker image and starting again?

So I missed a part of the docs:

Accessing the Sync Gateway Admin port from the container

By default, the port 4985, which is the Sync Gateway Admin port, is only accessible via localhost. This means that it’s only accessible from within the container.

To access it from within the container, you can get a bash shell on the running container and then use curl to connect to the admin port as follows:

$ docker exec -ti container-id bash
Note: replace container-id above with the actual running container id (ie, 9d004a24a4d1), which you can find by running docker ps | grep sync_gateway.
From the container shell (indicated by the # prompt), you can use curl to make requests against the running Sync Gateway by running:

curl http://localhost:4985

{“ADMIN”:true,“couchdb”:“Welcome”,“vendor”:{“name”:“Couchbase Sync Gateway”,“version”:1.3},“version”:“Couchbase Sync Gateway/1.3.0(274;8c3ee28)”}
Exposing accessing to the SyncGateway Admin port to the host

If you need to expose port 4985 to the host machine, you can do so with the following steps.

You may want to stop any currently running Sync Gateway containers with docker stop container-id.

Start a container with these arguments:

$ docker run -p 4984-4985:4984-4985 -d couchbase-sync-gateway -adminInterface :4985 /etc/sync_gateway/config.json
Now, from the host machine, you should be able to run a curl request against the admin port of 4985

I can now access the admin port :slight_smile: