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 0.0.0.0:4984-4985->4984-4985/tcp tiny_lumiere
adca39eea937 couchbase "/entrypoint.sh couch" 5 weeks ago Up 5 weeks 0.0.0.0:8091-8094->8091-8094/tcp, 11207/tcp, 11211/tcp, 0.0.0.0:11210->11210/tcp, 18091-18093/tcp db
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 http://0.0.0.0:4985 fails, but I’m unclear on the semantics of 0.0.0.0 as opposed to 127.0.0.1 or localhost. I suspect that 0.0.0.0 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.)
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:
{“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