dockercouchbasecouchbase-sync-gateway

SYNC gateway couldn't connect to couchbase server in a docker environment


I am trying to put CB and Sync Gateway instances in docker. I managed to launch CB Server (defined buckets, users and etc) but when SG fails with the following error message after I do the following docker command:

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

the error message is:

 ~ % 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

Couchbase Server is running in its own container successfully and i can access the admin web UI and configured users and buckets.

the config.json is:

{
    "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}"
            
        }
    }
    }

Solution

  • 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",