首页 > 解决方案 > 无法使用非标准端口运行 couchbase 容器

问题描述

更新 04/09/20 (jj/mm/aaaa)

我尝试通过使用 couchbase 配置文件在自定义端口上运行我的 couchbase 实例。

docker run -d --privileged --memory 3200M --name bumblebase \
-v '$PWD/static_config:/opt/couchbase/etc/couchbase/static_config' \
-p 3456-3461:3456-3461 -p 6575-6576:6575-6576 \
couchbase:community-6.6.0

static_config 是我按照此页面说明(底部)创建的具有以下内容的文件:

{rest_port, 3456}.
{query_port, 3458}.
{fts_http_port, 3459}.
{cbas_http_port, 3460}.
{eventing_http_port, 3461}.
{memcached_port, 6575}.

但是我根本无法访问我的 couchbase 实例(Web UI 或 rest api)。我试图将我的本地端口指向自定义和默认端口(-p 3456-3461:8091-8096),但没有一个工作,只有当我删除 -v 选项时问题才会消失 - 这让我回到原来的帖子场景.

附带说明一下,到目前为止,我仍在尝试使用设置替代地址,但没有任何成功。出于某种原因,当我设置备用主机名(这似乎是运行所必需的)时,访问备用地址需要很长时间才能加载最终失败并出现超时错误。

原帖

由于我开发了许多运行不同 couchbase 集群的应用程序,因此我必须在不同端口的容器中运行它们。我使用以下命令创建了我的容器:

docker run -d --memory 2048M --name "my-database" \
    -p 3456-3461:8091-8096 \
    -p 6210-6211:11210-11211 \
    couchbase

然后我添加了存储桶,并在 localhost:3456 的 Web UI 上运行正常:

在此处输入图像描述

这是我的服务器信息:

在此处输入图像描述

在我的代码中,我有以下连接功能:

var cluster *gocb.Cluster

func Cluster() *gocb.Cluster {
    return cluster
}

func init() {]
    c, err := gocb.Connect(
        "couchbase://127.0.0.1:3456",
        gocb.ClusterOptions{
            Username: "Administrator",
            Password: "password",
            TimeoutsConfig: gocb.TimeoutsConfig{
                ConnectTimeout: 30 * time.Second,
            },
        },
    )

    if err != nil {
        panic(err)
    }

    cluster = c
}

恐慌不会触发,但每当我尝试执行 KV 操作时,它都会失败并出现以下错误:

ambiguous timeout | {"InnerError":{"InnerError":{"InnerError":{},"Message":"ambiguous timeout"}},"OperationID":"Add","Opaque":"0x0","TimeObserved":2501547947,"RetryReasons":null,"RetryAttempts":0,"LastDispatchedTo":"","LastDispatchedFrom":"","LastConnectionID":""}

只有当我尝试连接到我的 docker couchbase 实例时才会出现此错误。如果我运行 Couchbase Server 应用程序并连接到适当的端口(8091),它工作得非常好:

var cluster *gocb.Cluster

func Cluster() *gocb.Cluster {
    return cluster
}

func init() {]
    c, err := gocb.Connect(
        "couchbase://localhost",
        gocb.ClusterOptions{
            Username: "Administrator",
            Password: "password",
            TimeoutsConfig: gocb.TimeoutsConfig{
                ConnectTimeout: 30 * time.Second,
            },
        },
    )

    if err != nil {
        panic(err)
    }

    cluster = c
}

我检查了凭据,它们是正确的,也用 0.0.0.0 或 127.0.0.1 替换 localhost 根本没有帮助。

标签: dockergocouchbase

解决方案


推荐阅读