2

I've been able to access Mysql console on a Mariadb Docker container.

From my local machine I can run this command to access the console (I have mariadb installed locally):

mysql -h localhost -P 3306 -u lc -p --protocol tcp

The issue rise when I try to use Docker secrets instead of explicitly writing password on the docker-compose.yml file.

Working configuration

So, with this I can access mysql console:

services:
  mariadb:
    image: mariadb
    environment:
      MYSQL_DATABASE: my_db
      MYSQL_ROOT_PASSWORD: 'pw'
    volumes:
      - db_data:/var/lib/mysql
    ports:
      - '3306:3306'

Issue

As soon as I move the secrets to a file, I cannot access anymore.

services:
  mariadb:
    image: mariadb
    environment:
      MYSQL_DATABASE: my_db
      MYSQL_ROOT_PASSWORD: ./env/mysql_root_password.tx
    volumes:
      - db_data:/var/lib/mysql
    ports:
      - '3306:3306'

secrets:
  mysql_root_password:
    file: ./env/mysql_root_password.txt

The secrets work because the Wordpress container access it easily, so possibly the password pw is turned into something else when retrieved from a secret.

Any idea?

a.barbieri
  • 403
  • 1
  • 5
  • 7

1 Answers1

2

It's very subtle...

If you are using file the environmental variable needs _FILE suffix!

MYSQL_ROOT_PASSWORD -> MYSQL_ROOT_PASSWORD_FILE

Althoug it was a very silly mistake I'm not deleting the question as it might save someone else's time.

a.barbieri
  • 403
  • 1
  • 5
  • 7