Search code examples
mongodbdocker

dockerize mongoDB persist data to usb drive


I am developing a mongo database application. I am running out of room on my local hardrive. I moved my source code to my local usb drive and thought I would persist the data also on that local usb drive.

docker run -d --rm --name mongodb -v "/media/ken/My Passport/Projects/DOCKER/data":/data/db --network favorites-net mongo:5

this creates the basic file structure then the container crashes

The log is as follows:

{"t":{"$date":"2024-03-11T20:57:31.342+00:00"},"s":"I",  "c":"CONTROL",  "id":23285,   "ctx":"main","msg":"Automatically disabling TLS 1.0, to force-enable TLS 1.0 specify --sslDisabledProtocols 'none'"}
{"t":{"$date":"2024-03-11T20:57:31.342+00:00"},"s":"W",  "c":"ASIO",     "id":22601,   "ctx":"main","msg":"No TransportLayer configured during NetworkInterface startup"}
{"t":{"$date":"2024-03-11T20:57:31.342+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":"2024-03-11T20:57:31.343+00:00"},"s":"W",  "c":"ASIO",     "id":22601,   "ctx":"main","msg":"No TransportLayer configured during NetworkInterface startup"}
{"t":{"$date":"2024-03-11T20:57:31.343+00:00"},"s":"I",  "c":"REPL",     "id":5123008, "ctx":"main","msg":"Successfully registered PrimaryOnlyService","attr":{"service":"TenantMigrationDonorService","ns":"config.tenantMigrationDonors"}}
{"t":{"$date":"2024-03-11T20:57:31.343+00:00"},"s":"I",  "c":"REPL",     "id":5123008, "ctx":"main","msg":"Successfully registered PrimaryOnlyService","attr":{"service":"TenantMigrationRecipientService","ns":"config.tenantMigrationRecipients"}}
{"t":{"$date":"2024-03-11T20:57:31.343+00:00"},"s":"I",  "c":"CONTROL",  "id":5945603, "ctx":"main","msg":"Multi threading initialized"}
{"t":{"$date":"2024-03-11T20:57:31.344+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":"53c93c6e0e61"}}
{"t":{"$date":"2024-03-11T20:57:31.344+00:00"},"s":"I",  "c":"CONTROL",  "id":23403,   "ctx":"initandlisten","msg":"Build Info","attr":{"buildInfo":{"version":"5.0.25","gitVersion":"dab8c370be035063df257746cc1a2de1bf36bcd4","openSSLVersion":"OpenSSL 1.1.1f  31 Mar 2020","modules":[],"allocator":"tcmalloc","environment":{"distmod":"ubuntu2004","distarch":"x86_64","target_arch":"x86_64"}}}}
{"t":{"$date":"2024-03-11T20:57:31.344+00:00"},"s":"I",  "c":"CONTROL",  "id":51765,   "ctx":"initandlisten","msg":"Operating System","attr":{"os":{"name":"Ubuntu","version":"20.04"}}}
{"t":{"$date":"2024-03-11T20:57:31.344+00:00"},"s":"I",  "c":"CONTROL",  "id":21951,   "ctx":"initandlisten","msg":"Options set by command line","attr":{"options":{"net":{"bindIp":"*"}}}}
{"t":{"$date":"2024-03-11T20:57:31.345+00:00"},"s":"I",  "c":"STORAGE",  "id":22315,   "ctx":"initandlisten","msg":"Opening WiredTiger","attr":{"config":"create,cache_size=7453M,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":"2024-03-11T20:57:32.442+00:00"},"s":"E",  "c":"STORAGE",  "id":22435,   "ctx":"initandlisten","msg":"WiredTiger error","attr":{"error":17,"message":"[1710190652:442214][1:0x7fe0bfeaec80], connection: __posix_open_file, 815: /data/db/WiredTiger.wt: handle-open: open: File exists"}}
{"t":{"$date":"2024-03-11T20:57:32.442+00:00"},"s":"I",  "c":"STORAGE",  "id":22430,   "ctx":"initandlisten","msg":"WiredTiger message","attr":{"message":"unexpected file WiredTiger.wt found, renamed to WiredTiger.wt.3"}}
{"t":{"$date":"2024-03-11T20:57:32.443+00:00"},"s":"E",  "c":"STORAGE",  "id":22435,   "ctx":"initandlisten","msg":"WiredTiger error","attr":{"error":1,"message":"[1710190652:443486][1:0x7fe0bfeaec80], connection: __posix_open_file, 815: /data/db/WiredTiger.wt: handle-open: open: Operation not permitted"}}
{"t":{"$date":"2024-03-11T20:57:32.514+00:00"},"s":"E",  "c":"STORAGE",  "id":22435,   "ctx":"initandlisten","msg":"WiredTiger error","attr":{"error":17,"message":"[1710190652:514098][1:0x7fe0bfeaec80], connection: __posix_open_file, 815: /data/db/WiredTiger.wt: handle-open: open: File exists"}}
{"t":{"$date":"2024-03-11T20:57:32.515+00:00"},"s":"I",  "c":"STORAGE",  "id":22430,   "ctx":"initandlisten","msg":"WiredTiger message","attr":{"message":"unexpected file WiredTiger.wt found, renamed to WiredTiger.wt.4"}}
{"t":{"$date":"2024-03-11T20:57:32.516+00:00"},"s":"E",  "c":"STORAGE",  "id":22435,   "ctx":"initandlisten","msg":"WiredTiger error","attr":{"error":1,"message":"[1710190652:516011][1:0x7fe0bfeaec80], connection: __posix_open_file, 815: /data/db/WiredTiger.wt: handle-open: open: Operation not permitted"}}
{"t":{"$date":"2024-03-11T20:57:32.551+00:00"},"s":"E",  "c":"STORAGE",  "id":22435,   "ctx":"initandlisten","msg":"WiredTiger error","attr":{"error":17,"message":"[1710190652:551930][1:0x7fe0bfeaec80], connection: __posix_open_file, 815: /data/db/WiredTiger.wt: handle-open: open: File exists"}}
{"t":{"$date":"2024-03-11T20:57:32.553+00:00"},"s":"I",  "c":"STORAGE",  "id":22430,   "ctx":"initandlisten","msg":"WiredTiger message","attr":{"message":"unexpected file WiredTiger.wt found, renamed to WiredTiger.wt.5"}}
{"t":{"$date":"2024-03-11T20:57:32.553+00:00"},"s":"E",  "c":"STORAGE",  "id":22435,   "ctx":"initandlisten","msg":"WiredTiger error","attr":{"error":1,"message":"[1710190652:553824][1:0x7fe0bfeaec80], connection: __posix_open_file, 815: /data/db/WiredTiger.wt: handle-open: open: Operation not permitted"}}
{"t":{"$date":"2024-03-11T20:57:32.556+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":"2024-03-11T20:57:32.556+00:00"},"s":"F",  "c":"STORAGE",  "id":28595,   "ctx":"initandlisten","msg":"Terminating.","attr":{"reason":"1: Operation not permitted"}}
{"t":{"$date":"2024-03-11T20:57:32.557+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":689}}
{"t":{"$date":"2024-03-11T20:57:32.557+00:00"},"s":"F",  "c":"-",        "id":23092,   "ctx":"initandlisten","msg":"\n\n***aborting after fassert() failure\n\n"}

The files describe by the log are created in a data directory on my usb drive.

I am not using "${PWD}" because I do have that space in the path and I wanted to be able to start from any prompt in my terminal. I did try it and get the same problem.

Question 1 can I persist the data to a bind mount on a usb drive Question 2 if yes then how if no, why not?

FYI my os is ubuntu 18.04


Solution

  • Mongo uses system calls for disk I/O. Any writable partition will do. USB will be dead slow, but I guess performance doesn't matter in this particular case.

    Docker adds it's own abstraction layer between guest OS (20.04) and the host OS (18.04) which may slow down disk IO, depending on FS driver used in docker.

    This particular error message says:

    "unexpected file WiredTiger.wt found, renamed to WiredTiger.wt.3"

    "unexpected file WiredTiger.wt found, renamed to WiredTiger.wt.4"

    "unexpected file WiredTiger.wt found, renamed to WiredTiger.wt.5"

    This may be due to an unsupported upgrade or downgrade.

    It's hard to misinterpret the message - the files in /media/ken/My Passport/Projects/DOCKER/data are not from mongodb v5.0.25.

    Map an empty directory to the container and let mongo to init file structure.