【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的容器卷,所以一直使用的就是原来容器卷中保存的密码,换一个容器卷或者删掉原来的就可以了。

你可能感兴趣的:(docker,mysql,容器)