【docker-compose.yml 中设置了 mysql 的MYSQL_ROOT_PASSWORD未生效】

如题,在docker中部署mysql,部署成功后密码与环境参数的MYSQL_ROOT_PASSWORD不一致,百度了很久也没找到答案。google了一下,在S.O上看到一条回答,马上就知道自己多蠢了。

配置信息如下:

 mysql:
    image: mysql:8.0
    environment:
      MYSQL_ROOT_PASSWORD: ${MYSQL_ROOT_PASSWORD}
    volumes:
      - ${DATA_PATH_HOST}/mysql:/var/lib/mysql
    ports:
      - ${MYSQL_PORT}:3306
    networks:
      - backend

原答主内容:

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 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
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 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

解决:
因为存在之前的mysql的容器卷,所以一直使用的就是原来容器卷中保存的密码,换一个容器卷或者删掉原来的就可以了。

  • 3
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值