Create a couchbase bucket during build of the container

We are using docker to automate the develop environments through docker compose. We use couchbase heavily in our applications. One problem we faced is that if you boot up the docker image of couchbase, you will have to manually perform the setup process, create buckets and so on. Performing all of these steps manually and everytime is time consuming and not at all ideal.

I will show you how we solved this problem and automated these steps through Dockerfile

The key thing here is that Couchbase exposes a set of services to perform each of the operation which can be invoked just after the server start.

We are using docker-compose and hence our docker-compose.yml is as follows:

version : ' 2' services : couchbase : build : couchbase/ ports : - 8091:8091 - 8092:8092 - 8093:8093 - 11210:11210

Through build: couchbase/ , I am pointing to a couchbase directory which contains our Dockerfile and a script configure-node.sh which invokes the REST API endpoints of couchbase.

Here is the very simplistic Dockerfile

FROM couchbase:community-3.1.3 COPY configure-node.sh /opt/couchbase CMD ["/opt/couchbase/configure-node.sh"]

We use the following script to configure the node.

All the files are given in this github repo