简体   繁体   中英

Why does MySQL Docker container complain that MYSQL_ROOT_PASSWORD env must be defined when using Docker 17.03 secrets?

I'm trying to adapt Docker's Wordpress secret example (link below) to work in my Docker Compose setup (for Drupal).

https://docs.docker.com/engine/swarm/secrets/#/advanced-example-use-secrets-with-a-wordpress-service

However, when the 'mysql' container is spun up, the following error is output:

"error: database is uninitialized and password option is not specified You need to specify one of MYSQL_ROOT_PASSWORD, MYSQL_ALLOW_EMPTY_PASSWORD and MYSQL_RANDOM_ROOT_PASSWORD"

I created the secrets using the 'docker secret create' command:

docker secret create mysql_root_pw tmp-file-holding-root-pw.txt
docker secret create mysql_pw tmp-file-holding-pw.txt

After running the above, the secrets ' mysql_root_pw ' and ' mysql_pw ' now exist in the swarm environment. Verified by doing:

docker secret ls

Here are the relevant parts from my docker-compose.yml file:

version: '3.1'
services:
  mysql:
    image: mysql/mysql-server:5.7.17 
   environment:
      - MYSQL_ROOT_PASSWORD_FILE="/run/secrets/mysql_root_pw"
      - MYSQL_PASSWORD_FILE="/run/secrets/mysql_pw"
    secrets:
      - mysql_pw
      - mysql_root_pw

secrets:
  mysql_pw:
    external: true
  mysql_root_pw:
    external: true

When I do " docker stack deploy MYSTACK ", I get the error mentioned above when the 'mysql' container attempts to start.

It seems like " MYSQL_PASSWORD_FILE " and " MYSQL_ROOT_PASSWORD_FILE " are not standard environment variables recognized by MySQL, and it's still expecting " MYSQL_ROOT_PASSWORD " environment variable.

I'm using Docker 17.03.

Any suggestions?

Thanks.

You get this error if your secret is a empty string as well. That is what happened to me, secret is mounted and service properly configured, but still fails because there is not password.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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