码头工人,MYSQL_ROOT_PASSWORD 不起作用 [英] docker, MYSQL_ROOT_PASSWORD do not work
问题描述
docker-compose:
docker-compose:
mysql:
image: mysql:5.7.16
container_name: f_mysql
volumes:
- ./db:/var/lib/mysql
environment:
MYSQL_ROOT_PASSWORD: sheep
expose:
- '3306'
我用docker exec
输入这个容器,
然后我输入echo $MYSQL_ROOT_PASSWORD
,然后我得到sheep
,
and I type echo $MYSQL_ROOT_PASSWORD
, then I got sheep
,
但是mysql的root密码还是'',
but the mysql root password still is '',
当我输入'mysql -uroot'时,我登录了mysql.
when I type 'mysql -uroot', I login mysql.
推荐答案
指定env变量的格式是正确的,都可以使用
The format for specifying env variables is correct, you can use either
environment:
MYSQL_ROOT_PASSWORD: a_password
或
environment:
- MYSQL_ROOT_PASSWORD=a_password
对我来说,问题是我使用随机密码选项集创建了 db 卷,然后禁用了它,但没有清除该卷.因此,无论我对 docker-compose 文件做了什么更改,带有旧登录信息的旧卷仍然存在.
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.
我不得不 docker volume ls
找到该卷,然后 docker volume rm
将其删除.重新启动后,一切正常.
I had to docker volume ls
to find the volume then docker volume rm <name>
to remove it. After re-upping, everything worked.
这篇关于码头工人,MYSQL_ROOT_PASSWORD 不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!