Azure应用服务中的MongoDB,通过Docker-Compose

jjhzyzn0  于 2023-04-05  发布在  Docker
关注(0)|答案(1)|浏览(124)

我将保持这一点非常简单,因为我已经回到了这个基础--我的容器配置有点复杂,但这真的很快就演示了这个问题。
我有以下Azure应用服务的docker-compose:

version: '3.4'
services:

  mongo:
    image: myrepo/myrepo:mongo-1
    restart: always
    volumes:
      - mongo:/var/mydata
    environment:
      MONGO_INITDB_ROOT_USERNAME: xxx
      MONGO_INITDB_ROOT_PASSWORD: xxx
    ports:
      - "27017:27107"
    networks:
      - app-network

volumes:
  mongo:
    driver: azure_file
    driver_opts:
      share_name: mongo
      storage_account_name: xxx
      storage_account_key: xxx

networks:
  app-network:

没有什么花哨的。然后我创建了一个自定义的Mongo图像如下:

FROM mongo
EXPOSE 27017
 
ENTRYPOINT ["mongod", "--dbpath=/var/mydata", "--bind_ip_all"]

我在其他地方读到过,挂载到/data/db是个坏主意,因为它会导致问题--所以我坚持这些指导方针。
Azure文件共享似乎配置正确。但是,当我启动容器时,我在Mongo启动期间收到重复的错误消息,即它无法打开WiredTiger.wt -并尝试重复创建新的。我可以从完全空的文件共享开始-它仍然这样做。Mongo正在共享中创建文件。
我已经绞尽脑汁了,因为我已经尝试了很多建议(太多了,在这里无法提及),但我根本无法解决这个问题。
任何我可能错过的将大大收到。文件权限似乎是罚款,因为我可以触摸和/或删除一个文件从共享没有问题-它似乎只是Mongo与问题。
非常感谢。

更新

下面是容器运行时的一些输出-您可以看到它已经尝试了几次WiredTiger文件:

2023-02-26T20:41:30.809321991Z {"t":{"$date":"2023-02-26T20:41:30.809+00:00"},"s":"I",  "c":"WT",       "id":22430,   "ctx":"initandlisten","msg":"WiredTiger message","attr":{"message":{"ts_sec":1677444090,"ts_usec":809021,"thread":"14:0x7dfcbbc19cc0","session_name":"connection","category":"WT_VERB_BLOCK","category_id":3,"verbose_level":"NOTICE","verbose_level_id":-1,"msg":"unexpected file WiredTiger.wt found, renamed to WiredTiger.wt.7"}}}
2023-02-26T20:41:30.840231616Z {"t":{"$date":"2023-02-26T20:41:30.839+00:00"},"s":"E",  "c":"WT",       "id":22435,   "ctx":"initandlisten","msg":"WiredTiger error message","attr":{"error":1,"message":{"ts_sec":1677444090,"ts_usec":839910,"thread":"14:0x7dfcbbc19cc0","session_name":"connection","category":"WT_VERB_DEFAULT","category_id":9,"verbose_level":"ERROR","verbose_level_id":-3,"msg":"__posix_open_file:805:/var/mydata/WiredTiger.wt: handle-open: open","error_str":"Operation not permitted","error_code":1}}}
2023-02-26T20:41:31.002537945Z {"t":{"$date":"2023-02-26T20:41:31.002+00:00"},"s":"E",  "c":"WT",       "id":22435,   "ctx":"initandlisten","msg":"WiredTiger error message","attr":{"error":17,"message":{"ts_sec":1677444091,"ts_usec":2211,"thread":"14:0x7dfcbbc19cc0","session_name":"connection","category":"WT_VERB_DEFAULT","category_id":9,"verbose_level":"ERROR","verbose_level_id":-3,"msg":"__posix_open_file:805:/var/mydata/WiredTiger.wt: handle-open: open","error_str":"File exists","error_code":17}}}
2023-02-26T20:41:31.050284867Z {"t":{"$date":"2023-02-26T20:41:31.050+00:00"},"s":"I",  "c":"WT",       "id":22430,   "ctx":"initandlisten","msg":"WiredTiger message","attr":{"message":{"ts_sec":1677444091,"ts_usec":50047,"thread":"14:0x7dfcbbc19cc0","session_name":"connection","category":"WT_VERB_BLOCK","category_id":3,"verbose_level":"NOTICE","verbose_level_id":-1,"msg":"unexpected file WiredTiger.wt found, renamed to WiredTiger.wt.8"}}}
2023-02-26T20:41:31.080410844Z {"t":{"$date":"2023-02-26T20:41:31.080+00:00"},"s":"E",  "c":"WT",       "id":22435,   "ctx":"initandlisten","msg":"WiredTiger error message","attr":{"error":1,"message":{"ts_sec":1677444091,"ts_usec":80113,"thread":"14:0x7dfcbbc19cc0","session_name":"connection","category":"WT_VERB_DEFAULT","category_id":9,"verbose_level":"ERROR","verbose_level_id":-3,"msg":"__posix_open_file:805:/var/mydata/WiredTiger.wt: handle-open: open","error_str":"Operation not permitted","error_code":1}}}
2023-02-26T20:41:31.097099487Z {"t":{"$date":"2023-02-26T20:41:31.096+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."}
2023-02-26T20:41:31.097778289Z {"t":{"$date":"2023-02-26T20:41:31.097+00:00"},"s":"F",  "c":"STORAGE",  "id":28595,   "ctx":"initandlisten","msg":"Terminating.","attr":{"reason":"1: Operation not permitted"}}
2023-02-26T20:41:31.098377890Z {"t":{"$date":"2023-02-26T20:41:31.097+00:00"},"s":"F",  "c":"ASSERT",   "id":23091,   "ctx":"initandlisten","msg":"Fatal assertion","attr":{"msgid":28595,"file":"src/mongo/db/storage/wiredtiger/wiredtiger_kv_engine.cpp","line":708}}

这几乎就像是有某种权限问题可能?我显然使用了正确的文件共享密钥等.否则我的测试命令将无法工作.我已经尝试chown/chgrp root以防万一-没有区别(不是我认为它会)-使用以下:

CMD [ "sh", "-c", "ls -l /var; touch /var/mydata/test.txt; rm /var/mydata/test.txt; chmod -R 777 /var/mydata; chown -R root /var/mydata; chgrp root /var/mydata; mongod --dbpath=/var/mydata --bind_ip_all" ]

只是重申一下--Azure文件共享是否为空并不重要--它将始终重试WiredTiger文件大约8次,直到容器放弃并终止。

更新#2

我还尝试创建一个自定义镜像,复制一个包含db路径等的Mongo配置文件,而不是使用命令行参数或环境变量进行docker-compose -仍然没有乐趣。

9q78igpj

9q78igpj1#

我在尝试使用Azure存储帐户设置持久存储时遇到了与您相同的问题,并最终找到了解决方案。
Azure文件共享似乎与MongoDB的底层存储驱动程序WiredTiger不兼容。我不知道确切的原因,但我也无法通过更改权限,创建自定义映像等来解决它。
解决方案是使用Azure Cosmos DB for MongoDB。Cosmos中的MongoDB API允许您利用现有的Mongo库,因此您应该能够以最小的代码更改使用它。我所要做的就是将我的mongo连接字符串替换为Cosmos提供的连接字符串。
以下是帮助您开始的文档:https://learn.microsoft.com/en-us/azure/cosmos-db/mongodb/introduction
希望这对你有帮助,祝你好运!

相关问题