mysql docker-compose启动异常:Database is uninitialized and password option is not specified

## docker-compose 定义,无法正常执行
version: '3.2'

services:
  mysql:
    image: mysql:5.7.35
    ports:
      - "3306:3306"
    environment:
      - MYSQL_ROOT_PASSWORD:abc
    restart: always
    volumes:
      - ./conf:/etc/mysql/conf.d
      - ./data:/var/lib/mysql

## 官方启动命令,可正常执行
## docker run -v "$PWD/data":/var/lib/mysql --name mysql57 -e MYSQL_ROOT_PASSWORD=abc-p3306:3306 -d mysql:5.7.35      

按上面的配置进行启动,但是总是提示环境变量未配置

mysql_1  | 2021-09-05 02:42:12+00:00 [ERROR] [Entrypoint]: Database is uninitialized and password option is not specified
mysql_1  |     You need to specify one of the following:
mysql_1  |     - MYSQL_ROOT_PASSWORD
mysql_1  |     - MYSQL_ALLOW_EMPTY_PASSWORD
mysql_1  |     - MYSQL_RANDOM_ROOT_PASSWORD

对比两种写法的差异后,可以发现
原因是:mysql的环境变量识别需要通过"="进行赋值,使用":"不生效.这也真是坑啊

正确的环境变量赋值方式

  MYSQL_ROOT_PASSWORD=abc
  • 参考资料

Docker | Postgres Database is uninitialized and superuser password is not specified
docker-compose environment-variables

posted @ 2021-09-05 10:58  橙木鱼  阅读(5410)  评论(0编辑  收藏  举报