1

I am using below docker compose file and using docker compose up command to run this container

I want the data of Mongo to persist

Note: I am using Docker Desktop on Windows 10, Version is same in both runs, Disk has permission (the first run is successful)

    version: '3.7'
services:
  mongodb_dev:
    image: 'mongo:5.0.9'
    container_name: 'mongo_example'
    environment:
      MONGO_INITDB_ROOT_USERNAME: ankit
      MONGO_INITDB_ROOT_PASSWORD: password1234
      MONGO_INITDB_DATABASE: testdb
    ports:
      - 27017:27017
    volumes:
      - ./init-mongo.js:/docker-entrypoint-initdb.d/init-mongo-js:ro
      - c:\mongo_data:/data/db

Operation is successful if c:\mongo_data folder is empty but once mongo puts in files and I restart the container it gives me below error

{"t":{"$date":"2022-06-21T14:30:42.551+00:00"},"s":"I",  "c":"CONTROL",  "id":23285,   "ctx":"-","msg":"Automatically disabling TLS 1.0, to force-enable TLS 1.0 specify --sslDisabledProtocols 'none'"}

{"t":{"$date":"2022-06-21T14:30:42.553+00:00"},"s":"I",  "c":"NETWORK",  "id":4915701, "ctx":"-","msg":"Initialized wire specification","attr":{"spec":{"incomingExternalClient":{"minWireVersion":0,"maxWireVersion":13},"incomingInternalClient":{"minWireVersion":0,"maxWireVersion":13},"outgoing":{"minWireVersion":0,"maxWireVersion":13},"isInternalClient":true}}}

{"t":{"$date":"2022-06-21T14:30:42.553+00:00"},"s":"W",  "c":"ASIO",     "id":22601,   "ctx":"main","msg":"No TransportLayer configured during NetworkInterface startup"}

{"t":{"$date":"2022-06-21T14:30:42.553+00:00"},"s":"I",  "c":"NETWORK",  "id":4648601, "ctx":"main","msg":"Implicit TCP FastOpen unavailable. If TCP FastOpen is required, set tcpFastOpenServer, tcpFastOpenClient, and tcpFastOpenQueueSize."}

{"t":{"$date":"2022-06-21T14:30:42.555+00:00"},"s":"W",  "c":"ASIO",     "id":22601,   "ctx":"main","msg":"No TransportLayer configured during NetworkInterface startup"}

{"t":{"$date":"2022-06-21T14:30:42.555+00:00"},"s":"I",  "c":"REPL",     "id":5123008, "ctx":"main","msg":"Successfully registered PrimaryOnlyService","attr":{"service":"TenantMigrationDonorService","ns":"config.tenantMigrationDonors"}}

{"t":{"$date":"2022-06-21T14:30:42.555+00:00"},"s":"I",  "c":"REPL",     "id":5123008, "ctx":"main","msg":"Successfully registered PrimaryOnlyService","attr":{"service":"TenantMigrationRecipientService","ns":"config.tenantMigrationRecipients"}}

{"t":{"$date":"2022-06-21T14:30:42.555+00:00"},"s":"I",  "c":"CONTROL",  "id":5945603, "ctx":"main","msg":"Multi threading initialized"}

{"t":{"$date":"2022-06-21T14:30:42.556+00:00"},"s":"I",  "c":"CONTROL",  "id":4615611, "ctx":"initandlisten","msg":"MongoDB starting","attr":{"pid":1,"port":27017,"dbPath":"/data/db","architecture":"64-bit","host":"9c35105d0bbc"}}

{"t":{"$date":"2022-06-21T14:30:42.556+00:00"},"s":"I",  "c":"CONTROL",  "id":23403,   "ctx":"initandlisten","msg":"Build Info","attr":{"buildInfo":{"version":"5.0.9","gitVersion":"6f7dae919422dcd7f4892c10ff20cdc721ad00e6","openSSLVersion":"OpenSSL 1.1.1f  31 Mar 2020","modules":[],"allocator":"tcmalloc","environment":{"distmod":"ubuntu2004","distarch":"x86_64","target_arch":"x86_64"}}}}

{"t":{"$date":"2022-06-21T14:30:42.556+00:00"},"s":"I",  "c":"CONTROL",  "id":51765,   "ctx":"initandlisten","msg":"Operating System","attr":{"os":{"name":"Ubuntu","version":"20.04"}}}

{"t":{"$date":"2022-06-21T14:30:42.556+00:00"},"s":"I",  "c":"CONTROL",  "id":21951,   "ctx":"initandlisten","msg":"Options set by command line","attr":{"options":{"net":{"bindIp":"*"},"security":{"authorization":"enabled"}}}}

{"t":{"$date":"2022-06-21T14:30:42.571+00:00"},"s":"I",  "c":"STORAGE",  "id":22270,   "ctx":"initandlisten","msg":"Storage engine to use detected by data files","attr":{"dbpath":"/data/db","storageEngine":"wiredTiger"}}

{"t":{"$date":"2022-06-21T14:30:42.581+00:00"},"s":"I",  "c":"STORAGE",  "id":22315,   "ctx":"initandlisten","msg":"Opening WiredTiger","attr":{"config":"create,cache_size=480M,session_max=33000,eviction=(threads_min=4,threads_max=4),config_base=false,statistics=(fast),log=(enabled=true,archive=true,path=journal,compressor=snappy),builtin_extension_config=(zstd=(compression_level=6)),file_manager=(close_idle_time=600,close_scan_interval=10,close_handle_minimum=250),statistics_log=(wait=0),verbose=[recovery_progress,checkpoint_progress,compact_progress],"}}

{"t":{"$date":"2022-06-21T14:30:43.127+00:00"},"s":"E",  "c":"STORAGE",  "id":22435,   "ctx":"initandlisten","msg":"WiredTiger error","attr":{"error":1,"message":"[1655821843:127036][1:0x7f01f90c4c80], file:WiredTiger.wt, connection: __posix_open_file, 808: /data/db/WiredTiger.wt: handle-open: open: Operation not permitted"}}

{"t":{"$date":"2022-06-21T14:30:43.208+00:00"},"s":"E",  "c":"STORAGE",  "id":22435,   "ctx":"initandlisten","msg":"WiredTiger error","attr":{"error":1,"message":"[1655821843:208300][1:0x7f01f90c4c80], file:WiredTiger.wt, connection: __posix_open_file, 808: /data/db/WiredTiger.wt: handle-open: open: Operation not permitted"}}

{"t":{"$date":"2022-06-21T14:30:43.283+00:00"},"s":"E",  "c":"STORAGE",  "id":22435,   "ctx":"initandlisten","msg":"WiredTiger error","attr":{"error":1,"message":"[1655821843:283775][1:0x7f01f90c4c80], file:WiredTiger.wt, connection: __posix_open_file, 808: /data/db/WiredTiger.wt: handle-open: open: Operation not permitted"}}

{"t":{"$date":"2022-06-21T14:30:43.287+00:00"},"s":"W",  "c":"STORAGE",  "id":22347,   "ctx":"initandlisten","msg":"Failed to start up WiredTiger under any compatibility version. This may be due to an unsupported upgrade or downgrade."}

{"t":{"$date":"2022-06-21T14:30:43.287+00:00"},"s":"F",  "c":"STORAGE",  "id":28595,   "ctx":"initandlisten","msg":"Terminating.","attr":{"reason":"1: Operation not permitted"}}

{"t":{"$date":"2022-06-21T14:30:43.287+00:00"},"s":"F",  "c":"-",        "id":23091,   "ctx":"initandlisten","msg":"Fatal assertion","attr":{"msgid":28595,"file":"src/mongo/db/storage/wiredtiger/wiredtiger_kv_engine.cpp","line":687}}

{"t":{"$date":"2022-06-21T14:30:43.287+00:00"},"s":"F",  "c":"-",        "id":23092,   "ctx":"initandlisten","msg":"\n\n***aborting after fassert() failure\n\n"}

Code of init-mongo.js

db.createUser(
   {
     user: "myuser",
     pwd: "strongpassword",
     roles: [ "readWrite", "dbAdmin" ]
   }
)
Ankit
  • 6,388
  • 8
  • 54
  • 79
  • dbPath seems to be /data/db. Do you have permission to this folder? – Gibbs Jun 24 '22 at 04:50
  • And you have added volumes in dockerfile. But it should be like `mongodata: ` – Gibbs Jun 24 '22 at 04:51
  • Did you change versions while performing these operations? Like initially one version, later another version. – Gibbs Jun 24 '22 at 04:52
  • Version is same. I just stopped the Mongo container and started it again after it stopped – Ankit Jun 24 '22 at 15:41
  • Is your dbPath correct? – Gibbs Jun 24 '22 at 18:51
  • Where is dbPath? If its the path where DB files are saved, than it is correct. Note that the DB starts if folder is empty and I am able to create collections and add documents. Its only after restart (with same config) it doesnt load and gives error – Ankit Jun 24 '22 at 19:07
  • Do you have any other container that shares the same path? Check if any other process is locking it. – Alex Blex Jun 24 '22 at 21:38
  • No other container shares the same path – Ankit Jun 27 '22 at 12:46
  • @Gibbs, `mongodata:` is for volume mounting, `:` is for "bind mounting". by the way, this compose content and the paths are working fine. problem is somewhere else, maybe in that init script. – Yılmaz Durmaz Jun 29 '22 at 01:13
  • 1
    You're using a Linux docker in windows with mounted volumes. As mongodb runs as mongo user, that user sort of gets lost in restart (it's a new user), so you can only read the files, but not write. Follow instructions in https://stackoverflow.com/questions/29245216/write-in-shared-volumes-docker/29251160#29251160 – Robbie Jun 30 '22 at 13:18
  • I noticed this message in the logs "Failed to start up WiredTiger under any compatibility version. This may be due to an unsupported upgrade or downgrade.". Are you using a fresh-empty data folder, or trying to mount an old one? – Yılmaz Durmaz Jul 03 '22 at 21:43

2 Answers2

0

This is Permission issue for the location C:\mongo_data. If I remember right, go to C:\\ -> Right Click on mongo_data -> Properties -> Permissions give them read and write permissions.

This should solve your problem.

Raja Ravindra
  • 303
  • 2
  • 9
  • Docker has full permissions on this folder as its able to read and write to this folder on first run. – Ankit Jun 24 '22 at 13:44
0

I have run your compose file content with a dummy init script file.

Docker had no problem starting the server. I have tested first with pre-created folder on D drive, and then with no matching folder on C drive. docker created data folder on C itself. I have also created that folder as admin, there still no problem occured.

I could not replicate your issue with the information you gave. So the problem is not with the compose content you gave above.

I suggest you first check your init script content to see if it can break anything, then other service definitions in your compose file. if possible give them both here so we can test more.

PS: It was even interesting to see that if I somehow try to start the server from two different consoles, the one I started later will just attach itself to the already started container.

Yılmaz Durmaz
  • 2,374
  • 12
  • 26
  • I have added code for init-mongo.js. It is simple script to create a user – Ankit Jun 29 '22 at 13:49
  • 1
    @Ankit, can you try a different folder name and also try using D drive or any other hdd/ssd? other than fixing `init-mongo-js:ro` to `init-mongo.js:ro`, nothing has changed: everything works fine on my side. remove/rename existing folders, do not create them yourself and let docker create it. check what happens, then remove them again and create manually. – Yılmaz Durmaz Jun 29 '22 at 15:15
  • I tried your suggestion and it worked for first time. When I restarted by system, I got the same error when I started the docker for mongo. Note - I changed nothing in between, just rebooted the system – Ankit Jun 30 '22 at 18:07
  • @Ankit, this one is really weird. it seems to work perfectly on my side. try to have that data folder in your user space `C:\Users\youruser\mongo_data`. if this gives the same error, then I would say something else in your system or the docker installation is broken. – Yılmaz Durmaz Jul 03 '22 at 21:38