[英]“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 :
# 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
$ docker stack deploy --compose-file=docker-compose.yml my_db_stack
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_password
和mongodb/.mongodb_root_username
文件中的Windows 样式的行结尾引起的。 Those files were created on the Windows host, and then (I assume) were blindly copied to the container.这些文件是在 Windows 主机上创建的,然后(我假设)被盲目地复制到容器中。
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.