我正在设置一个 Docker 容器,使用 Docker Compose 初始化 Mongo DB 副本集。但是我无法完成此操作。我已经创建了 Docker Compose 来调用三个 Mongo 实例,但是我遇到解析器问题。以下是我的 Docker-Compose 文件。
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"
这是我的设置 Dockerfile 文件位于./setup文件夹中,通过它进行调用。
FROM mongo
# Create app directory
WORKDIR vauto-docker/src/config
# Install app dependencies
COPY replicaSet.js .
COPY setup.sh .
CMD ["./setup.sh"]
该过程会调用 replicaSet.js 和 setup.sh。以下是 replicaSet.js 和 setup.sh 文件。
# 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:
Dockerfile 的内容如下:
FROM mongo
WORKDIR vauto-docker/src/config
copy mongo.conf .
EXPOSE 27017
CMD ["--config","./mongo.conf"]
我的mongo.conf文件中有以下代码:
replication:
oplogSizeMB: 1024
replSetName: vAUTO
我遇到了以下错误:
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