Couldn't start Sync Gateway in Docker

First time docker user. I managed to launch CB Server (defined buckets, users and etc) but when SG fails with the following error message:

 ~ % docker logs unruffled_jennings

2023-03-02T13:54:22.004Z ==== Couchbase Sync Gateway/3.0.5(8;godeps/) EE ====

2023-03-02T13:54:22.005Z [INF] Loading content from [https://config/sg-config.json] ...

2023-03-02T13:54:22.879Z [INF] Found unknown fields in startup config. Attempting to read as legacy config.

2023-03-02T13:54:22.879Z [INF] Loading content from [https://config/sg-config.json] ...

2023-03-02T13:54:23.070Z [INF] Config is a legacy config, and disable_persistent_config was not requested. Attempting automatic config upgrade.

2023-03-02T13:54:23.075Z [WRN] gocb: Pipeline Client 0x40002940e0 failed to bootstrap: check server ports and cluster encryption setting: dial tcp 127.0.0.1:11210: connect: connection refused -- base.GoCBCoreLogger.Log() at logger_external.go:80

2023-03-02T13:54:26.075Z [WRN] gocb: CCCPPOLL: Failed to retrieve CCCP config. check server ports and cluster encryption setting: dial tcp 127.0.0.1:11210: connect: connection refused -- base.GoCBCoreLogger.Log() at logger_external.go:80

2023-03-02T13:54:26.075Z [WRN] gocb: CCCPPOLL: Failed to retrieve config from any node. -- base.GoCBCoreLogger.Log() at logger_external.go:80

2023-03-02T13:54:28.076Z [WRN] gocb: Pipeline Client 0x40002940e0 failed to bootstrap: check server ports and cluster encryption setting: dial tcp 127.0.0.1:11210: connect: connection refused -- base.GoCBCoreLogger.Log() at logger_external.go:80

2023-03-02T13:54:31.582Z [WRN] gocb: CCCPPOLL: Failed to retrieve CCCP config. check server ports and cluster encryption setting: dial tcp 127.0.0.1:11210: connect: connection refused -- base.GoCBCoreLogger.Log() at logger_external.go:80

2023-03-02T13:54:31.582Z [WRN] gocb: CCCPPOLL: Failed to retrieve config from any node. -- base.GoCBCoreLogger.Log() at logger_external.go:80

2023-03-02T13:54:33.075Z [ERR] Couldn't start Sync Gateway: unambiguous timeout | {"InnerError":{"InnerError":{"InnerError":{},"Message":"unambiguous timeout"}},"OperationID":"WaitUntilReady","Opaque":"","TimeObserved":10000218462,"RetryReasons":["NOT_READY"],"RetryAttempts":15,"LastDispatchedTo":"","LastDispatchedFrom":"","LastConnectionID":""} -- rest.ServerMain() at main.go:26

the command I used for SyncGateway is

docker run -p 4984:4984 -d couchbase/sync-gateway https://config/sg-config.json

my config.json file:

{
    "log": [
        ""
    ],
    "databases": {
        "db": {
            "server": "http://127.0.0.1:8091",
            "bucket": "test_bucket",
            "username": "username",
            "password": "pwdpwdpwd",
            "enable_shared_bucket_access": true,
            "num_index_replicas": 0,
            "import_docs": true,
            "users": {
                "GUEST": {
                    "disabled": true
                },
                "username": {
                    "password": "pwdpwdpwd",
                    "admin_channels": [
                        ""
                    ]
                },
            },
            "sync": "function(doc, oldDoc) {\n  if (doc.replRole) {\n    requireRole('replicator');\n    if (doc.replRole !== 'replicator') {\n      requireRole(doc.replRole);\n      channel(doc.replRole);\n      if (doc.channels && doc.channels.length) {\n        doc.channels.each(function(channel) {\n          channel(doc.replRole + '_' + channel);\n        });\n      }\n    }\n  } else {\n    requireRole('sync_daemon');\n    channel(doc.channels);\n  }\n}"
            
        }
    }
    }

In a different machine, I installed them both without docker and both have started. I am in MacOS (M1 if that matters).

CB inspect returns the following:


Ports

11207/tcp Not bound

---

11210/tcp 0.0.0.0:11210

---

11210/tcp :::11210

---

11211/tcp Not bound

---

18091/tcp Not bound

---

18092/tcp Not bound

---

18093/tcp Not bound

---

18094/tcp Not bound

---

18095/tcp Not bound

---

18096/tcp Not bound

---

8091/tcp 0.0.0.0:8091

---

8091/tcp :::8091

---

8092/tcp 0.0.0.0:8092

---

8092/tcp :::8092

---

8093/tcp 0.0.0.0:8093

---

8093/tcp :::8093

---

8094/tcp 0.0.0.0:8094

---

8094/tcp :::8094

---

8095/tcp Not bound

---

8096/tcp Not bound

I just answered this on SO but reposting here:

The config

"server": "http://127.0.0.1:8091",

Is telling Sync Gateway to try finding Couchbase Server on port 8091 inside the Sync Gateway container, which in almost all cases isn’t going to be the right thing to do. You’ll have to specify the correct address for the container running Couchbase Server.

Docker Networking is a whole topic by itself, and there are many approaches, but in general the following three examples should work well enough to get you up and running.

For example, routing directly to a Docker container’s IP:

"server": "http://172.17.0.16:8091",

Or, if you want to route through a bound port on the host:

"server": "http://172.17.0.1:8091",

Or using a container hostname:

"server": "http://cb-server:8091",

thanks so much yes. Finally, both CB and SG are running well but SG docker logs show this:

c:test_bucket-SG Error processing DCP stream - will attempt to restart/reconnect if appropriate: worker connect, server: 172.18.0.2:11210, err: dial tcp 172.18.0.2:11210: connect: connection timed out. -- base.(*DCPReceiver).OnError() at dcp_receiver.go:60

I don’t see any documents in my CB database. What could be the cause of the error?

You’ll need to call this endpoint from Couchbase server (Naming a Node | Couchbase Docs), with with https://nip.io/ as the hostname i.e. 172.18.0.2.nip.io

pardon @mohammedcb can you tell me more please. Call it from where?

You can do

curl -X POST -u Administrator:password \
http://172.18.0.2:8091/node/controller/rename \
-d hostname=' 172.18.0.2.nip.io'

from a command line and it should fix your problem

I faced the same issue, for the Couchbase helm chart on kubernetes local cluster. For me disabling WSL 2 in docker general settings, worked out pretty well. Run docker desktop on Hyper - V and sync gateway without any issues.