5

A mongodb container is successfully created based on below docker-compose configuration:

mongodb:
    build: ./mongodb
    container_name: iboorse_mongo
    restart: unless-stopped
    command: mongod --auth --config /etc/mongod.conf
    environment:
      - MONGO_INITDB_ROOT_USERNAME
      - MONGO_INITDB_ROOT_PASSWORD
      - MONGO_INITDB_USERNAME
      - MONGO_INITDB_PASSWORD
      - MONGO_INITDB_DATABASE
    volumes:
      - ./mongodb/001_init-mongo.sh:/docker-entrypoint-initdb.d/001_init-mongo.sh
      - ./mongodb/mongod.conf:/etc/mongod.conf
      - mongo-data:/data/db
    ports:
      - ${MONGO_EXPOSED_PORT}:27017

after some time, some data was stored in the DB but got the below error. the container is being terminated immediately after it starts. (so I don't have enough time to connect to the container and investigate the problem).

error: unexpected "js-yaml.js" output while parsing config

mongodb.conf:

# mongod.conf

# for documentation of all options, see:
#   http://docs.mongodb.org/manual/reference/configuration-options/

# Where and how to store data.
storage:
  dbPath: /data/db
  journal:
    enabled: true
#  engine:
#  mmapv1:
#  wiredTiger:

# where to write logging data.
# systemLog:
#   destination: file
#   logAppend: true
#   path: /data/mongod.log

# network interfaces
net:
  port: 27017
  bindIpAll: true
  # bindIp: 127.0.0.1


# how the process runs
processManagement:
  timeZoneInfo: /usr/share/zoneinfo

security:
  authorization: 'enabled'

#operationProfiling:

#replication:

#sharding:

## Enterprise-Only Options:

#auditLog:

#snmp:

any help would be appreciated!

Vahid Kiani
  • 89
  • 1
  • 5
  • I have the same problem, did you get anywhere in resolving it? Thanks! – Nahko Sep 08 '22 at 12:18
  • 1
    I couldn't find the root of the issue, unfortunately. I ended up applying a daily backup strategy and doing less docker restart on the MongoDB container to prevent losing data. – Vahid Kiani Sep 08 '22 at 13:40

2 Answers2

0

Not using Docker Compose here, but Kubernetes. I ran into the exact same issue. In a long and tedious debugging session, I figured out that the script docker-entrypoint.sh uses mongosh to load the script /js-yaml.js, that further converts your MongoDB YAML configuration into JSON. Loading that script failed and caused mongosh crash with a non-meaningful "Killed" message.

The cause of that crash is usually insufficient resources. In my case, I had explicitely limited the container's memory to only 128Mi which had been far from enough. I increased it to 512Mi and the error was gone.

Solution (for me): Check your memory limits and increase them if needed.

Monkey Supersonic
  • 1,165
  • 1
  • 10
  • 19
0

In my case (upgrade mongo in docker from 5.0.x to 6.0.x), use -f instead of --config will resolve it.

Banehallow
  • 141
  • 1
  • 1
  • 6