I am setting up a docker container to initialize the Mongo DB replica set using docker compose. I am not able to get this done. I have created docker-compose to invoke three mongo instance but i am getting parser issue. Below is my Docker-Compose file.
version: '3'
services:
mongo-vauto-1:
image: "mongo-start"
build: ./mongo-vAUTO-1
ports:
- "30000:27017"
volumes:
- ./mongo-vAUTO-1/data:/data/db
depends_on:
- "mongo-vauto-2"
- "mongo-vauto-3"
mongo-vauto-2:
image: "mongo"
command: --replSet vAUTO --smallfiles --oplogSize 128
ports:
- "40000:27017"
volumes:
- ./mongo-vAUTO-2/data:/data/db
mongo-vauto-3:
image: "mongo"
command: --replSet vAUTO --smallfiles --oplogSize 128
ports:
- "50000:27017"
volumes:
- ./mongo-vAUTO-3/data:/data/db
mongo-setup-vauto:
image: "mongo-setup-vauto"
build: ./setup
depends_on:
- "mongo-vauto-1"
which invokes Dockerfile which is in ./setup folder. Below is my set up Dockerfile
FROM mongo
# Create app directory
WORKDIR vauto-docker/src/config
# Install app dependencies
COPY replicaSet.js .
COPY setup.sh .
CMD ["./setup.sh"]
which invokes replicaSet.js and setup.sh. The replicaSet.js and setup.sh files are provided below
# replicaSet.js
rsconf = {
_id : "vAUTO",
members: [
{_id : 0, host : "mongo-vauto-1:27017"},
{_id : 1, host : "mongo-vauto-2:27017"},
{_id : 2, host : "mongo-vauto-3:27017"}
]
}
rs.initiate(rsconf);
rs.conf();
# setup.sh
echo *********************************
echo Starting the replica set
echo *********************************
sleep 10 | echo waiting for the replica set to be intialized
mongo mongodb://mongo-vauto-1:27017 replicaSet.js
Dockerfile for first replica set is given below
FROM mongo
WORKDIR vauto-docker/src/config
copy mongo.conf .
EXPOSE 27017
CMD ["--config","./mongo.conf"]
and my mongo.conf file has the following code
replication:
oplogSizeMB: 1024
replSetName: vAUTO
I am getting the following error,
mongo-vauto-1_1 | parse error: Invalid numeric literal at line 1, column 14
mongo-vauto-1_1 | parse error: Invalid numeric literal at line 1, column 14
mongo-vauto-1_1 | Error parsing YAML config file: yaml-cpp: error at line 3, column 1: illegal tab when looking for indentation