2017-06-02 417 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官方码头工人图像处理所有这些给你。