[英]MongoDB docker - Error initializing docker if folder is not empty
我正在使用下面的 docker compose 文件並使用 docker compose up 命令來運行這個容器
我希望 Mongo 的數據能夠持久化
注意:我在 Windows 10 上使用 Docker Desktop,兩次運行版本相同,磁盤有權限(第一次運行成功)
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
如果 c:\mongo_data 文件夾為空,則操作成功,但是一旦 mongo 放入文件並重新啟動容器,它會給我以下錯誤
{"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"}
init-mongo.js 的代碼
db.createUser(
{
user: "myuser",
pwd: "strongpassword",
roles: [ "readWrite", "dbAdmin" ]
}
)
這是位置C:\mongo_data
的權限問題。 如果我沒記錯的話,去C:\\ -> Right Click on mongo_data -> Properties -> Permissions
給他們讀寫權限。
這應該可以解決您的問題。
我已經使用虛擬初始化腳本文件運行了您的撰寫文件內容。
Docker 啟動服務器沒有問題。 我首先在 D 盤上使用預先創建的文件夾進行了測試,然后在 C 盤上沒有匹配的文件夾進行測試。 docker 在 C 本身上創建了數據文件夾。 我還以管理員身份創建了該文件夾,仍然沒有出現問題。
我無法用您提供的信息復制您的問題。 所以問題不在於你上面給出的撰寫內容。
我建議您首先檢查您的 init 腳本內容以查看它是否會破壞任何內容,然后檢查 compose 文件中的其他服務定義。 如果可能的話,把它們都給這里,這樣我們就可以測試更多。
PS:甚至有趣的是,如果我以某種方式嘗試從兩個不同的控制台啟動服務器,我稍后啟動的那個只會將自己附加到已經啟動的容器上。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.