A memo when building a local environment of Couchbase with Docker
There was a local environment for Vagrant, --Startup and build are heavy --No code (black boxed) --Vagrant No one on the team understands (because of the environment created by the person who left the company) There are problems such as.
Replace the local environment with Docker.
First, let's launch the Couchbase container without making detailed settings.
-Check the image at Couchbase docker hub repository
→ Since the version of the production environment is 4.5.1
, use community-4.5.1
.
--Start the container
For the time being, start as described in Description
$ docker run -d --name db -p 8091-8094:8091-8094 -p 11210:11210 couchbase:community-4.5.1
--Container startup confirmation
$ docker ps
↓ Start OK
--Console operation check
Access http://0.0.0.0:8091/
with a browser and confirm that the Couchbase console is displayed.
You can manually set the account and bucket by pressing Setup
, but since the purpose is coding, we will skip it here.
Check the operation for the time being. ..
Create Dockerfile, docker-compose.yaml
The following settings are required to set up the local environment. --Create cluster --Service settings --Couchbase server credentials settings --Bucket creation --View settings
Dockerfile (also docker-compose.yaml) is described in order to put the above settings into the code.
#Directory structure
local-env
├ docker-compose.yaml
└ mbe-couchbase-container
├ byfield
│ └ all.ddoc #view definition file
├ Dockerfile #Couchbase Docker file
└ configure.sh #Bash script to configure Couchbase
# docker-compose.yaml
version: "3.7"
services:
mbe-couchbase:
build: ./mbe-couchbase-container
ports:
- 8091:8091
- 8092:8092
- 8093:8093
- 8094:8094
- 11210:11210
- 11211:11211
environment:
- COUCHBASE_ADMINISTRATOR_USERNAME=couchbase
- COUCHBASE_ADMINISTRATOR_PASSWORD=lcouchbase1
--Set Couchbase credentials with COUCHBASE_ADMINISTRATOR_USERNAME
,COUCHBASE_ADMINISTRATOR_PASSWORD
--In build: ./mbe-couchbase-container
, specify ↓ Dockerfile
#Create Dockerfile
FROM couchbase:community-4.5.1
#Copy the Couchbase initialization shell into the container
COPY ./configure.sh /opt/couchbase
COPY ./byfield/ /opt/couchbase
#Couchbase configuration execution shell
CMD [ "/opt/couchbase/configure.sh" ]
#Couchbase configuration shell
set -m
#Server startup
/entrypoint.sh couchbase-server &
#Roughly set the waiting time until the API server starts TODO:I want to detect server startup and proceed with processing.
sleep 30
#Cluster memory allocation
curl -v -X POST http://127.0.0.1:8091/pools/default -d memoryQuota=4096 -d indexMemoryQuota=4096
#Service settings
curl -v http://127.0.0.1:8091/node/controller/setupServices -d services=kv%2cn1ql%2Cindex
#Couchbase server credentials settings
curl -v http://127.0.0.1:8091/settings/web -d port=8091 -d username=$COUCHBASE_ADMINISTRATOR_USERNAME -d password=$COUCHBASE_ADMINISTRATOR_PASSWORD
#Bucket cap lift(The maximum number of buckets is 10 by default,,If you want to create more, you need to change with the following settings)
curl -v -u $COUCHBASE_ADMINISTRATOR_USERNAME:$COUCHBASE_ADMINISTRATOR_PASSWORD -X POST http://127.0.0.1:8091/internalSettings -d maxBucketCount=20
#Bucket creation
curl -v -u $COUCHBASE_ADMINISTRATOR_USERNAME:$COUCHBASE_ADMINISTRATOR_PASSWORD -X POST http://127.0.0.1:8091/pools/default/buckets -d name=bucket_name -d bucketType=couchbase -d ramQuotaMB=100 -d authType=sasl -d saslPassword=ladd_personal_info1
echo "please wait 30 sec..."
sleep 30
#View settings
curl -v -u $COUCHBASE_ADMINISTRATOR_USERNAME:$COUCHBASE_ADMINISTRATOR_PASSWORD -X PUT -H "Content-Type: application/json" http://127.0.0.1:8092/bucket_name/_design/api%2Ftest -d @/opt/couchbase/all.ddoc
sleep 15
#Foreground execution
fg 1
--Container execution with docker-compose
$ docker-compose up -d mbe-couchbase
Confirm bucket startup.
Couchbase doesn't find many articles even if I google. The official reference was solid and it was just a simple implementation so I didn't have any problems. .. Is Couchbase not popular? It seems that the cloud version came out a while ago, but I don't think it will be used when relocating to the cloud.
https://blog.couchbase.com/docker-deploy-containerized-java-couchbase-web-application/
Recommended Posts