Docker Secrets for MariaDB Stack Container

Hello,

If I create a Docker stack with secrets for Drupal + MariaDB, then I can’t log into the MariaDB, but without secrets I can log in. So it could be because of the secrets.

First I created a network, then secrets and then the docker stack.
Before I used echo for secrets, but now printf, because I read that echo adds newlines: Mariadb - creation with docker secrets not working - #2 by aptalca - Container Support - LinuxServer.io , but still it doesn’t work

docker network create --driver overlay drupal
printf "password1" | docker secret create mariadb-pw -
printf "strongpw1" | docker secret create mariadb-root-pw -
docker stack deploy --compose-file drupal-stack1.yml drupal
The Stack Compose File
version: "3.9"

networks:
  drupal:
    external: true

volumes:
  drupal-modules:
  drupal-profiles:
  drupal-sites:
  drupal-themes:
  mariadb-vol:

secrets:
  mariadb-pw:
    external: true
  mariadb-root-pw:
    external: true

services:
  drupal:
    image: drupal
    deploy:
      replicas: 3
    networks:
      - drupal
    ports:
      - 8080:80
    environment:
      MYSQL_DATABASE: drupal-db
      MYSQL_USER: besucher
      MYSQL_PASSWORD: /run/secrets/mariadb-pw
      MYSQL_ROOT_PASSWORD: /run/secrets/mariadb-root-pw
    volumes:
      - drupal-modules:/var/www/html/modules
      - drupal-profiles:/var/www/html/profiles
      - drupal-sites:/var/www/html/sites
      - drupal-themes:/var/www/html/themes
    secrets:
      - mariadb-root-pw
      - mariadb-pw
 
  mariadb:
    image: mariadb
    deploy:
      replicas: 1
    networks:
      - drupal
    environment:
      MARIADB_DATABASE: drupal-db
      MARIADB_ROOT_PASSWORD: /run/secrets/mariadb-root-pw
      MARIADB_USER: besucher
      MARIADB_PASSWORD: /run/secrets/mariadb-pw
    volumes:
      - mariadb-vol:/var/lib/mysql
    secrets:
      - mariadb-root-pw
      - mariadb-pw

Did you read the doc?

As an alternative to passing sensitive information via environment variables, _FILE may be appended to the previously listed environment variables, causing the initialization script to load the values for those variables from files present in the container.