3

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:

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.
  • latest mongo image from docker hub (version 4.2.8)
  • docker secrets to manage the authentication credentials to the MongoDB database
  • 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
$ 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.

Sharkovsky87
  • 133
  • 9

1 Answers1

3

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. Those files were created on the Windows host, and then (I assume) were blindly copied to the container.

Solution

Using notepad++ I switched the line endings to Unix-style, which solved the problem.

To switch the line endings, I right-clicked the highlighted portion of the bottom bar in the image below, on Notepad++. Notepad highlight line endings

Sharkovsky87
  • 133
  • 9