I’m running into an issue where calling rs.initiate() crashes the mongodb server:
mongodb | ############## 1 ######################
mongodb | MongoServerError: This node was not started with replication enabled.
mongodb | {"t":{"$date":"2024-02-15T14:45:59.613+00:00"},"s":"I", "c":"NETWORK", "id":22944, "ctx":"conn13","msg":"Connection ended","attr":{"remote":"127.0.0.1:57268","uuid":{"uuid":{"$uuid":"14a10ead-f3a9-4b34-a054-16458c102c8b"}},"connectionId":13,"connectionCount":4}}
mongodb | {"t":{"$date":"2024-02-15T14:45:59.613+00:00"},"s":"I", "c":"NETWORK", "id":22944, "ctx":"conn12","msg":"Connection ended","attr":{"remote":"127.0.0.1:57264","uuid":{"uuid":{"$uuid":"78b7e779-c5ba-4ef9-927b-4bbdf00c78c3"}},"connectionId":12,"connectionCount":3}}
mongodb | {"t":{"$date":"2024-02-15T14:45:59.613+00:00"},"s":"I", "c":"NETWORK", "id":22944, "ctx":"conn10","msg":"Connection ended","attr":{"remote":"127.0.0.1:57246","uuid":{"uuid":{"$uuid":"0183b0ca-8220-4e75-be58-4ed280c066ce"}},"connectionId":10,"connectionCount":2}}
mongodb | {"t":{"$date":"2024-02-15T14:45:59.613+00:00"},"s":"I", "c":"NETWORK", "id":22944, "ctx":"conn9","msg":"Connection ended","attr":{"remote":"127.0.0.1:57244","uuid":{"uuid":{"$uuid":"93a6213a-b6e9-40ec-9d76-d148ecbf1f09"}},"connectionId":9,"connectionCount":1}}
mongodb | {"t":{"$date":"2024-02-15T14:45:59.613+00:00"},"s":"I", "c":"NETWORK", "id":22944, "ctx":"conn11","msg":"Connection ended","attr":{"remote":"127.0.0.1:57260","uuid":{"uuid":{"$uuid":"e323c3de-3c86-4eea-8d45-c87b2b3016f7"}},"connectionId":11,"connectionCount":0}}
mongodb exited with code 1
docker-compose:
mongo:
build:
dockerfile: Dockerfile
context: ./mongodb
container_name: mongodb
volumes:
- ./db/mongo:/data/db
- ./mongodb/init/startup.js:/docker-entrypoint-initdb.d/startup.js:ro
- ./mongodb/mongo.conf:/etc/mongo.conf:ro
env_file: .env
extra_hosts:
- "host.docker.internal:host-gateway"
ports:
- "127.0.0.1:27017:27017"
command: ["--replSet", "dbrs", "--bind_ip_all","--config", "/etc/mongo.conf"]
startup.js :
print("############## 1 ######################");
rs.initiate()
print("############## 2 ######################");
mongo.conf:
security:
authorization: enabled
keyFile: /keyfile
dockerfile:
FROM mongo:latest
ENV TZ="Etc/UTC"
ENV TIME_ZONE="Etc/UTC"
RUN apt update
RUN apt install openssl
RUN apt-get clean
RUN openssl rand -base64 741 > /keyfile
RUN chmod 600 /keyfile
RUN chown 999:999 /keyfile
I’m hitting a roadblock, can anyone help ?