Docker Compose无法正确链接到MySQL数据库

时间:2018-08-15 15:45:07

标签: mysql docker-compose

我有一个docker-compose,它将创建一个鳄梨酱docker容器,一个guacd容器和一个mysql容器。在docker主机上,我在/tmp/scripts

中有init.db文件。

如果要手动执行mysql部分,我将运行docker run --name guac-mysql -v /tmp/scripts:/tmp/scripts -e MYSQL_ROOT_PASSWORD=password -d mysql:5.7

然后像这样运行鳄梨酱容器:

docker run --name guacamole --link guacd:guacd --link mysql:mysql \
-e MYSQL_DATABASE='guacamole' \
-e MYSQL_USER='guacamole' \
-e MYSQL_PASSWORD='password' \
-d -p 8080:8080 guacamole/guacamole


version: '2'

services:
  guacd:
    hostname: guacd
    image: guacamole/guacd
  mysql:
    hostname: mysql
    image: mysql:5.7
    volumes:
      - ./tmp/scripts:/docker-entrypoint-initdb.d
    ports:
      - "3306:3306"
    environment:
      - MYSQL_DATABASE="guacamole"
      - MYSQL_USER="guacamole"
      - MYSQL_PASSWORD="password"
      - MYSQL_ROOT_PASSWORD:"password"
  guacamole:
    image: guacamole/guacamole
    restart: always
    ports:
      - "8080:8080"
    links:
      - guacd
      - mysql
   environment:
      - GUACD_HOSTNAME=guacd


volumes:
  tmp-scripts:

但是当我尝试使其自动化时,如下所示,出现此错误:

database is uninitialized and password option is not specified
  You need to specify one of MYSQL_ROOT_PASSWORD, MYSQL_ALLOW_EMPTY_PASSWORD and MYSQL_RANDOM_ROOT_PASSWORD

可以帮忙吗?

谢谢

1 个答案:

答案 0 :(得分:1)

:=

MYSQL_ROOT_PASSWORD="password"