web-dev-qa-db-ja.com

DockerのCouchbaseとsync_gateway

DockerコンテナにCouchbaseとsync_gatewayを設定しようとしていますが、sync_gatewayがデータベースに接続しようとすると、奇妙な認証エラーが発生します。

Couchbaseはそのコンテナで正常に実行されており、sync_gatewayをGUESTユーザーを使用するように設定すると、couchbaseに接続できます。問題は、作成したユーザー名/パスワードを本当に使用したいので、couchbaseコンテナをセットアップすることです。

localhost:8091のWebインターフェイスからアクセスし、作成したユーザー名/パスワードでログインできるため、couchbaseが機能していることがわかります。しかし、sync_gatewayは、構成ファイルからユーザー名/パスワードを使用してアクセスしようとすると、以下に投稿したエラーを発生させます。

Dockerfile

FROM couchbase/server
ENTRYPOINT ["/code/scripts/entrypoint.sh", "couchbase-server"]

これはentrypoint.sh

#!/bin/bash

cb_cli() {
    ${CB_CLI} ${@} ${CREDENTIALS}
}

server_configured() {
    server_list=$(cb_cli server-list)
    return $([[ $? == 0 ]] && [[ $(echo ${server_list} | wc -l) != 0 ]])
}

setup_couchbase_server() {
   cb_cli cluster-init --cluster-ramsize=${RAM_SIZE} --cluster-username=admin --cluster-password=admin123
   cb_cli bucket-create --bucket-ramsize=${RAM_SIZE} --bucket=${BUCKET_NAME}
}

couchbase_config() {
    curl ${SERVER_ADDR} >&- 2>&-
    while [[ $? != 23 ]]; do
        sleep 3
        curl ${SERVER_ADDR}>&- 2>&-
    done

    ! server_configured && {
        echo "Setting up couchbase server..."
        setup_couchbase_server && echo "Setup complete"
    }
}

[[ "$1" == "couchbase-server" ]] && {
    /usr/sbin/runsvdir-start &
    couchbase_config
    echo "Starting Couchbase Server -- Web UI available at http://${SERVER_ADDR} and logs available in /opt/couchbase/var/lib/couchbase/logs"
    /usr/sbin/runsvdir-start
}

docker-compose.yml

version: '3'
services:
  couchbase_server:
    build: .
    ports:
      - "8091-8094:8091-8094"
      - "11210:11210"
    volumes:
      - .:/code
    environment:
      - CB_CLI=opt/couchbase/bin/couchbase-cli
      - SERVER_ADDR=localhost:8091
      - CREDENTIALS=-u admin -p admin123 -c localhost:8091
      - RAM_SIZE=1024
      - BUCKET_NAME=sync_gateway
  sync_gateway:
    image: couchbase/sync-gateway
    links:
      - "couchbase_server:db"
    depends_on:
      - couchbase_server
    volumes:
      - ./sync_gateway_config.json:/code
    command: /code
    ports:
      - 4984:4984
      - 4985:4985

sync_gateway_config.json

{
    "log": ["REST"],
    "interface": ":4984",
    "databases": {
        "sync_gateway": {
            "server": "http://db:8091",
            "username": "admin",
            "password": "admin123"
        }
    }
}

そして最後に、これは私が実行したときに得られるエラーですdocker-compose up

couchbase_server_1  | Setting up couchbase server...
couchbase_server_1  | SUCCESS: init/edit localhost
couchbase_server_1  | SUCCESS: bucket-create
couchbase_server_1  | Setup complete
couchbase_server_1  | Starting Couchbase Server -- Web UI available at
http://localhost:8091 and logs available in /opt/couchbase/var/lib
/couchbase/logs

sync_gateway_1      | 2017-03-28T11:29:51.240Z Opening Couchbase 
database sync_gateway on <http://db:8091> as user "admin"

sync_gateway_1      | _time=2017-03-28T11:29:51.262+00:00 _level=INFO
_msg=Non-healthy node; node details:

sync_gateway_1      | _time=2017-03-28T11:29:51.262+00:00 _level=INFO 
_msg=Hostname=172.20.0.2:8091, Status=warmup, 
CouchAPIBase=http://172.20.0.2:8092
/sync_gateway%2B87e2e410d0e9da0295091c6de9ae5ae7, 
ThisNode=true

sync_gateway_1      | 2017-03-28T11:29:51.262Z WARNING: Error 
installing Couchbase design doc: no available couch rest URLs --
db.installViews.func1() at database.go:577

sync_gateway_1      | _time=2017-03-28T11:29:51.263+00:00 _level=INFO
_msg= Trying with 
http://172.20.0.2:8091/pools/default/bucketsStreaming/sync_gateway

sync_gateway_1      | _time=2017-03-28T11:29:51.268+00:00 _level=INFO
_msg=Non-healthy node; node details:

sync_gateway_1      | _time=2017-03-28T11:29:51.268+00:00 _level=INFO
_msg=Hostname=172.20.0.2:8091, Status=warmup, 
CouchAPIBase=http://172.20.0.2:8092
/sync_gateway%2B87e2e410d0e9da0295091c6de9ae5ae7, ThisNode=true

sync_gateway_1      | 2017-03-28T11:29:51.268Z WARNING: Error 
installing Couchbase design doc: no available couch rest URLs -- 
db.installViews.func1() at database.go:577

sync_gateway_1      | _time=2017-03-28T11:29:51.272+00:00 _level=INFO
_msg=Got new configuration for bucket sync_gateway

sync_gateway_1      | _time=2017-03-28T11:29:51.279+00:00 _level=INFO
_msg=Non-healthy node; node details:

sync_gateway_1      | _time=2017-03-28T11:29:51.280+00:00 _level=INFO 
_msg=Hostname=172.20.0.2:8091, Status=warmup, 
CouchAPIBase=
http://172.20.0.2:8092/sync_gateway%2B87e2e410d0e9da0295091c6de9ae5ae7,
ThisNode=true

sync_gateway_1      | 2017-03-28T11:29:51.280Z WARNING: Error
installing Couchbase design doc: no available couch rest URLs -- 
db.installViews.func1() at database.go:577

sync_gateway_1      | _time=2017-03-28T11:29:51.301+00:00 _level=INFO
_msg=Non-healthy node; node details:

sync_gateway_1      | _time=2017-03-28T11:29:51.301+00:00 _level=INFO
_msg=Hostname=172.20.0.2:8091, Status=warmup, 
CouchAPIBase=http://172.20.0.2:8092
/sync_gateway%2B87e2e410d0e9da0295091c6de9ae5ae7, ThisNode=true

sync_gateway_1      | 2017-03-28T11:29:51.301Z WARNING: Error
installing Couchbase design doc: no available couch rest URLs -- 
db.installViews.func1() at database.go:577

sync_gateway_1      | _time=2017-03-28T11:29:51.330+00:00 _level=INFO
_msg=Got new configuration for bucket sync_gateway

sync_gateway_1      | _time=2017-03-28T11:29:51.342+00:00 _level=INFO
_msg= Trying with selected node 0

sync_gateway_1      | _time=2017-03-28T11:29:51.399+00:00 _level=INFO 
_msg= Trying with selected node 0

sync_gateway_1      | 2017-03-28T11:29:51.576Z WARNING: Error from Incr
in sequence allocator (0) - attempt (1/3): MCResponse status=AUTH_ERROR,
opcode=SASL_AUTH, opaque=0, msg: 
Auth failure -- db.(*sequenceAllocator).incrWithRetry() at
sequence_allocator.go:88

sync_gateway_1      | 2017-03-28T11:29:51.589Z WARNING: Error from Incr 
in sequence allocator (0) - attempt (2/3): MCResponse status=AUTH_ERROR, 
opcode=SASL_AUTH, opaque=0, msg: 
Auth failure -- db.(*sequenceAllocator).incrWithRetry() at 
sequence_allocator.go:88

sync_gateway_1      | 2017-03-28T11:29:51.602Z WARNING: Error from Incr 
in sequence allocator (0) - attempt (3/3): MCResponse status=AUTH_ERROR,
opcode=SASL_AUTH, opaque=0, msg:
Auth failure -- db.(*sequenceAllocator).incrWithRetry() at 
sequence_allocator.go:88

sync_gateway_1      | 2017-03-28T11:29:51.613Z WARNING: Too many unsuccessful 
Incr attempts in sequence allocator - giving up (0): MCResponse status=
AUTH_ERROR, opcode=SASL_AUTH, opaque=0, msg: Auth failure -- 
db.(*sequenceAllocator).incrWithRetry()
at sequence_allocator.go:94

sync_gateway_1      | 2017-03-28T11:29:51.613Z WARNING: 
Error from Incr in _reserveSequences(0): Unable to increment sequence:
MCResponse status=AUTH_ERROR, opcode=SASL_AUTH, opaque=0, msg: Auth failure -- 
db.(*sequenceAllocator)._reserveSequences() at sequence_allocator.go:65

sync_gateway_1      | 2017-03-28T11:29:51.613Z FATAL: 
Error opening database: Unable to increment sequence: 
MCResponse status=AUTH_ERROR, opcode=SASL_AUTH, opaque=0, msg: Auth failure --
rest.RunServer() at config.go:677
1
Fernando Cezar

これはトリッキーでしたが、設定ファイルのユーザー名とパスワードがカウチベースサーバーではなくバケットを参照していることが判明しました。答えは、バケットを作成するときにパスワードを含めることでした。私のsetup_couchbase_serverファイル内entrypoint.sh今は次のようになっています:

setup_couchbase_server() {
   cb_cli cluster-init --cluster-ramsize=${CB_RAM_SIZE}
   cb_cli bucket-create --bucket-ramsize=${CB_RAM_SIZE} --bucket=${CB_SYNC_GATEWAY_BUCKET} --bucket-password=bucket_pass
}

その場合、ユーザー名はバケット名と同じである必要があります。今では動作します。

1
Fernando Cezar