2017-06-02 234 views
1

當我在Dockerfile寬度爲CMD [ "./myscript.sh" ]的末尾執行時,我無法啓動mysql demon。但是,CMD [ "mysqld" ]的作品。無法在執行CMD腳本時在Dockerfile中啓動Mysql

Dockerfile

FROM mysql:5.7 
USER mysql 
COPY ./setconf.sh . 
COPY config/my.cnf /etc/mysql/conf.d 
CMD [ "./setconf.sh" ] 

# CMD ["mysqld"] 
# This command works ! 

我得到這個錯誤:

[ERROR] Can't open the mysql.plugin table. Please run mysql_upgrade to   create it 
[ERROR] Fatal error: Can't open and lock privilege tables: Table  'mysql.user' doesn't exist 

泊塢窗,compose.yml

mysql: 
    build: mysql 
    environment: 
     MYSQL_PASSWORD: pass 
     MYSQL_ROOT_PASSWORD: pass 
     HOST: mysql 
     MYSQL_ROOT_HOST: mysql 
    ports: 
     - "3306:3306" 

./setconf.sh

mysqld 

注:

  • 我做docker-compose down在每次嘗試
  • 我需要特殊的選項來運行mysql

的my.cnf

[mysqld] 
default-storage-engine = INNODB 
sql-mode = "STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION" 
transaction-isolation = READ-COMMITTED 
innodb_flush_log_at_trx_commit = 1 
init_connect = "set session autocommit=0" 
log_bin_trust_function_creators = 1 
max_sp_recursion_depth = 100 
lower_case_table_names = 1 
thread_stack = 256K 
max_allowed_packet = 16M 

Check the Detailled docker-compose logs

回答

1

我不知道一個很好的解決方案,但這裏是你可以用一種變通方法: 擺脫你CMD,並使用

CMD ["mysqld"] 

代替。然後你的腳本複製到/docker-entrypoint-initdb.d/:

COPY /configureDB.sh /docker-entrypoint-initdb.d/ 

你的腳本將盡快MySQL是開始執行。更多信息,請參見MySQL泊塢窗文檔:https://github.com/docker-library/docs/tree/master/mysql#initializing-a-fresh-instance

Initializing a fresh instance: When a container is started for the first time, a new database with the specified name will be created and initialized with the provided configuration variables. Furthermore, it will execute files with extensions .sh, .sql and .sql.gz that are found in /docker-entrypoint-initdb.d. Files will be executed in alphabetical order. You can easily populate your mysql services by mounting a SQL dump into that directory and provide custom images with contributed data. SQL files will be imported by default to the database specified by the MYSQL_DATABASE variable.

然而,這是不是你lokking的反應,我不知道爲什麼你不能從腳本啓動mysqld。

1

這很可能是因爲你沒有初始化你的數據庫而發生的。您需要運行

mysqld --initialize

mysqld --initialize-insecure(空的root密碼)

,如果你是第一次運行MySQL。

docker-entrypoint.shfile在mysql官方碼頭工人圖像處理所有這些給你。