docker, MYSQL_ROOT_PASSWORD do not work

docker, docker-compose

Solution

For me the issue was that I'd created the db volume with the random password option set, then disabled that, but hadn't cleared the volume. So no matter what changes I made to the docker-compose file, the old volume with the old login information was still there.

I had to `docker volume ls` to find the volume then `docker volume rm <name>` to remove it. After re-upping, everything worked.

Regarding other answers on this page, the format for specifying env variables is correct, you can use either

environment:
  MYSQL_ROOT_PASSWORD: a_password

OR

environment:
  - MYSQL_ROOT_PASSWORD=a_password

Problem

docker-compose: ``` mysql: image: mysql:5.7.16 container_name: f_mysql volumes: - ./db:/var/lib/mysql environment: MYSQL_ROOT_PASSWORD: sheep expose: - '3306' ``` and I use `docker exec` input this container, and I type `echo $MYSQL_ROOT_PASSWORD`, then I got `sheep`, but the mysql root password still is '', when I type 'mysql -uroot', I login mysql.

Original source