Skip to content

Instantly share code, notes, and snippets.

@etoews
Last active June 13, 2016 12:11
Show Gist options
  • Save etoews/9ab08d869b1724751a48707905e7fead to your computer and use it in GitHub Desktop.
Save etoews/9ab08d869b1724751a48707905e7fead to your computer and use it in GitHub Desktop.
Couchbase on Carina with Docker Swarm using an overlay network
$ docker-compose up -d
Creating couchbase_db_1
$ docker-compose scale db=2
WARNING: The "db" service specifies a port on the host. If multiple containers for this service are created on a single host, the port will clash.
Creating and starting couchbase_db_2 ... done
$ docker run -it --rm \
--net couchbase_backend \
arungupta/couchbase \
couchbase-cli \
server-add \
--cluster=`docker inspect couchbase_db_1 | jq -r .[0].NetworkSettings.Networks.couchbase_backend.IPAddress`:8091 \
--user Administrator \
--password password \
--server-add=`docker inspect couchbase_db_2 | jq -r .[0].NetworkSettings.Networks.couchbase_backend.IPAddress` \
--server-add-username=Administrator \
--server-add-password=password
SUCCESS: server-add 10.0.0.3:8091
$ open http://$(docker port couchbase_db_1 8091)
$ docker run -it --rm \
--net couchbase_backend \
arungupta/couchbase \
couchbase-cli \
rebalance \
--cluster=`docker inspect couchbase_db_1 | jq -r .[0].NetworkSettings.Networks.couchbase_backend.IPAddress`:8091 \
--user Administrator \
--password password
INFO: rebalancing . . .
SUCCESS: rebalanced cluster
$ docker-compose scale db=3
WARNING: The "db" service specifies a port on the host. If multiple containers for this service are created on a single host, the port will clash.
Creating and starting couchbase_db_3 ... done
$ docker run -it --rm \
--net couchbase_backend \
arungupta/couchbase \
couchbase-cli \
rebalance \
--cluster=`docker inspect couchbase_db_1 | jq -r .[0].NetworkSettings.Networks.couchbase_backend.IPAddress`:8091 \
--user Administrator \
--password password \
--server-add=`docker inspect couchbase_db_3 | jq -r .[0].NetworkSettings.Networks.couchbase_backend.IPAddress` \
--server-add-username=Administrator \
--server-add-password=password
SUCCESS: server-add 10.0.0.4:8091
INFO: rebalancing . . .
SUCCESS: rebalanced cluster
$ open http://$(docker port couchbase_db_1 8091)/index.html#sec=servers
# You shouldn't need `docker inspect couchbase_db_1 | jq -r .[0].NetworkSettings.Networks.couchbase_backend.IPAddress`
# You should just be able to refer to the containers by name. e.g. couchbase_db_1:8091
# However if you do, you get the error
# ERROR: unable to server-add couchbase_db_2:8091 (400) Bad Request
# ["Prepare join failed. Requested address \"couchbase_db_2\" is not allowed: short names are not allowed. Couchbase Server requires at least one dot in a name"]
version: "2"
services:
db:
image: arungupta/couchbase
networks:
- backend
expose:
- 8092
- 8093
- 11210
ports:
- 8091:8091
networks:
backend: {}
# Normally I'd never open port 8091 on a public IP address like that but it's convenient for this example.
# If you don't open it and only have under expose, you would need to run a temporary proxy like https://community.getcarina.com/t/connecting-to-db-via-terminal/143/7?u=etoews
# to be able to access it.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment