2016-09-24 22 views
3

我有一個碼頭工人,撰寫和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 

但數據庫沒有密碼。我該如何解決它?

+0

possible duplicat [docker,MYSQL \ _ROOT \ _PASSWORD不工作](http://stackoverflow.com/questions/40149880/docker-mysql-root-password-do-not-work) – mayo

回答

3

看起來你將MYSQL_ROOT_PASSWORD設置爲空。根據文檔,它是必需的。

https://hub.docker.com/_/mysql/

MYSQL_ROOT_PASSWORD

這個變量是強制的,指定將用於MySQL根超級用戶帳戶被設定的密碼。

3

根據documentation,而不是MYSQL_ROOT_PASSWORD:你必須使用-=,你也應該使用 '密碼' 的結果將是:

- MYSQL_ROOT_PASSWORD=some_password

在你的例子:

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