Docker-compose:数据库未初始化

新手上路,请多包涵

我对 docker-compose 和 mysql 有疑问:

码头工人-compose.yml

 version: '2'
  services:
   db:
    image: mysql
    volumes:
      - "./sito/db/:/var/lib/mysql"
    ports:
      - "3306:3306"
    restart: always
    environment:
      MYSQL_ROOT_PASSWORD:

   app:
    depends_on:
      - db
    image: eboraas/apache-php
    links:
      - db
    ports:
      - "80:80"
    volumes:
      - ./sito/:/var/www/html/

编写此容器时发生错误:

 Recreating phpapp_phpapache_1
Attaching to phpapp_db_1, phpapp_phpapache_1
db_1 | error: database is uninitialized and password option is not specified
db_1 | You need to specify one of MYSQL_ROOT_PASSWORD, MYSQL_ALLOW_EMPTY_PASSWORD and MYSQL_RANDOM_ROOT_PASSWORD
phpapache_1 | AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 172.30.0.3. Set the 'ServerName' directive globally to suppress this message
phpapp_db_1 exited with code 1
db_1 | error: database is uninitialized and password option is not specified
db_1 | You need to specify one of MYSQL_ROOT_PASSWORD, MYSQL_ALLOW_EMPTY_PASSWORD and MYSQL_RANDOM_ROOT_PASSWORD
db_1 | error: database is uninitialized and password option is not specified
db_1 | You need to specify one of MYSQL_ROOT_PASSWORD, MYSQL_ALLOW_EMPTY_PASSWORD and MYSQL_RANDOM_ROOT_PASSWORD
db_1 | error: database is uninitialized and password option is not specified
db_1 | You need to specify one of MYSQL_ROOT_PASSWORD, MYSQL_ALLOW_EMPTY_PASSWORD and MYSQL_RANDOM_ROOT_PASSWORD
db_1 | error: database is uninitialized and password option is not specified

但是数据库没有密码。我该如何解决?

原文由 Stefano 发布,翻译遵循 CC BY-SA 4.0 许可协议

阅读 1.2k
1 个回答

我只是想指出一些事情,如果在终端中使用 docker run 命令而不是 docker-compose,这将是命令:

 docker run -e MYSQL_ROOT_PASSWORD=password mysql_image

请注意,如果将 --- 放在 -e MYSQL_ROOT_PASSWORD=password 之后, mysql_image

原文由 Mo Ganji 发布,翻译遵循 CC BY-SA 4.0 许可协议

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题