2017-06-02 33 views
1

CMD [ "./myscript.sh" ]の最後にあるmysqldをbashスクリプトで実行すると、mysqlデーモンを起動できません。ただし、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が起動されるように実行されます。あなたがスクリプトからmysqldを開始カントなぜ私にはわからない、これはあなたがlokkingている応答ではありません、しかし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.

    :詳細は、MySQLのドッキングウィンドウのドキュメントを参照してください。

    1

    データベースが初期化されていない可能性があります。あなたが初めてMySQLを実行している場合

    mysqld --initialize

    または

    mysqld --initialize-insecure

    (空のルートパスワードの入力を)実行する必要があります。

    mysql公式ドッカーの画像のdocker-entrypoint.shfileがこれをすべて処理します。

    関連する問題