简体   繁体   English

“错误:无法添加用户”在 MongoDB docker 堆栈中使用 Windows 上的机密文件

[英]“Error: couldn't add user” in MongoDB docker stack using a secrets file on Windows

While trying to run a MongoDB docker instance with authorization managed by docker-secrets (with files), inspired by this blog post , I kept running into the following error:在尝试运行 MongoDB docker 实例时,授权由 docker-secrets (with files) 管理,受这篇博文的启发,我一直遇到以下错误:

2020-07-24T16:25:26.656+0000 E  QUERY    [js] uncaught exception: Error: couldn't add user: Error preflighting normalization: U_STRINGPREP_PROHIBITED_ERROR :

Setup设置

  • Windows machine running docker with a WSL2 backend. Windows 机器运行 docker 和 WSL2 后端。
  • latest mongo image from docker hub (version 4.2.8)来自 docker 集线器的最新 mongo映像(版本 4.2.8)
  • docker secrets to manage the authentication credentials to the MongoDB database docker 机密,用于管理 MongoDB 数据库的身份验证凭据
  • my composer file:我的作曲家文件:
# docker-compose.yml

version: '3.5'
services:
  my_db:
    image: mongo
    command: --auth
    environment:
      MONGO_INITDB_ROOT_PASSWORD_FILE: /run/secrets/mongodb_root_password
      MONGO_INITDB_ROOT_USERNAME_FILE: /run/secrets/mongodb_root_username
    secrets:
      - mongodb_root_password
      - mongodb_root_username
secrets:
  mongodb_root_password:
    - file: mongodb/.mongodb_root_password
  mongodb_root_username:
    - file: mongodb/.mongodb_root_username
  • shell command to deploy docker stack shell 命令部署 docker 堆栈
$ docker stack deploy --compose-file=docker-compose.yml my_db_stack

Problem问题

Unfortunately, the container kept dying.不幸的是,容器不断死亡。 In the logs, I was able to find the error mentioned above.在日志中,我能够找到上面提到的错误。

It turns out that the problem was caused by Windows-style line endings in the mongodb/.mongodb_root_password and mongodb/.mongodb_root_username files.事实证明,问题是由mongodb/.mongodb_root_passwordmongodb/.mongodb_root_username文件中的Windows 样式的行结尾引起的。 Those files were created on the Windows host, and then (I assume) were blindly copied to the container.这些文件是在 Windows 主机上创建的,然后(我假设)被盲目地复制到容器中。

Solution解决方案

Using notepad++ I switched the line endings to Unix-style, which solved the problem.使用记事本++,我将行尾切换为 Unix 样式,从而解决了问题。

To switch the line endings, I right-clicked the highlighted portion of the bottom bar in the image below, on Notepad++.要切换行尾,我在 Notepad++ 上右键单击下图中底部栏的突出显示部分。 记事本突出显示行尾

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM