Couchbase Dockerfile for creating Clusters

Hi, I am trying to setup a Couchbase server and make cluster init on dockerfile.
Here is My Dockerfile

# syntax=docker/dockerfile:1
FROM couchbase:community-7.2.0

RUN sleep 20

RUN couchbase-cli cluster-init \
--cluster-username Administrator \
--cluster-password password \
--services data,index,query \
--cluster-ramsize 512 \
--cluster-index-ramsize 256

And here is my docker-compose.yml

services:
  couchbase:
    build:
      dockerfile: Dockerfile_Couchbase
    #image: "couchbase:community-7.2.0"
    ports:
      - "8091:8091"

And when I call docker compose up, It gives that error

[couchbase 3/3] RUN couchbase-cli cluster-init --cluster-username Administrator --cluster-password password --services data,index,query --cluster-ramsize 512 --cluster-index-ramsize 256:
#0 0.886 ERROR: Unable to connect to host at http://127.0.0.1:8091: HTTPConnectionPool(host=‘127.0.0.1’, port=8091): Max retries exceeded with url: /pools (Caused by NewConnectionError(‘<urllib3.connection.HTTPConnection object at 0x7f7b37f35ee0>: Failed to establish a new connection: [Errno 111] Connection refused’))

What will be the problem, thanks for reading and answering

Is there a reason you don’t want to use our official docker image? Install Couchbase Server Using Docker | Couchbase Docs

I have to use CLI. I checked link you send, but It requires UI to configure initial cluster.

I understand. It doesn’t require using the UI, that’s just the examples that are provided.

You should still be able to do what you’re looking to do. I’m not sure exactly why the couchbase-cli command is failing within the dockerfile, I suspect it either has to do with not waiting long enough for the server to have finished starting up, or perhaps it’s trying to reference the wrong IP (though I’d think 127.0.0.1 should work properly from within the container). Can you add a ‘-vv’ to the couchbase-cli command to see what the extended output is? And, just as a test, are you able to access the node through the UI to confirm it’s up and running?

A couple other options:

Both of the above have extracted the couchbase-cli commands into a separate script that runs rather than embedding the commands into the dockerfile.

Lastly, if your goal here is integrated testing from your applicaiton, I’d suggest looking at using testcontainers which handles all of this for you: Couchbase Module - Testcontainers for Java

1 Like

Hello, thanks for replies again, It says unrecognized arguments: -vv

Both of the above have extracted the couchbase-cli commands into a separate script that runs rather than embedding the commands into the dockerfile.

I am trying to achieve this using only dockerfile. When I disable run command in dockerfile I can visit UI through browser. It greets me with Start New Cluster.

My purpose is try CDC on couchbase with my current data.

Another option that I forgot to mention, this one is pretty well maintained: GitHub - brantburnett/couchbasefakeit: Docker scripts for a base Couchbase Server image for testing/development, with support for fakeit for data generation

After reading about docker, it seems impossible to cluster init in dockerfile with CMD or RUN commands, Special shell script required to accomplish it, which runs entrypoint.sh along side

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.