解決Windows Docker 客戶端使用 Mariadb 官方image啟動報錯

Posted by Y Cheung on Mon, Sep 17, 2018

MariaDB Image使用的是當前最新的v10.3版本

1docker pull mariadb:latest

docker-compose.yml文件內容:

 1version: "3"
 2services:
 3  mariadb:
 4    image: mariadb
 5    container_name: mariadb
 6    restart: always
 7    volumes:
 8      - ${DATA_DIR}:/var/lib/mysql
 9    ports:
10      - "3306:3306"
11    environment:
12      MYSQL_ROOT_PASSWORD: password
13      MYSQL_DATABASE: public

.env 文件內容:

1DATA_DIR=d:/data

容器起來後沒多久就掛掉重啟,查看log信息:

 12018-09-17 13:25:21 0 [Note] mysqld (mysqld 10.3.9-MariaDB-1:10.3.9+maria~bionic) starting as process 1 ...
 22018-09-17 13:25:21 0 [Note] InnoDB: Using Linux native AIO
 32018-09-17 13:25:21 0 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
 42018-09-17 13:25:21 0 [Note] InnoDB: Uses event mutexes
 52018-09-17 13:25:21 0 [Note] InnoDB: Compressed tables use zlib 1.2.11
 62018-09-17 13:25:21 0 [Note] InnoDB: Number of pools: 1
 72018-09-17 13:25:21 0 [Note] InnoDB: Using SSE2 crc32 instructions
 82018-09-17 13:25:21 0 [Note] InnoDB: Initializing buffer pool, total size = 256M, instances = 1, chunk size = 128M
 92018-09-17 13:25:21 0 [Note] InnoDB: Completed initialization of buffer pool
102018-09-17 13:25:21 0 [Note] InnoDB: If the mysqld execution user is authorized, page cleaner thread priority can be changed. See the man page of setpriority().
112018-09-17 13:25:21 0 [ERROR] InnoDB: The Auto-extending innodb_system data file './ibdata1' is of a different size 0 pages than specified in the .cnf file: initial 768 pages, max 0 (relevant if non-zero) pages!
122018-09-17 13:25:21 0 [ERROR] InnoDB: Plugin initialization aborted with error Generic error
132018-09-17 13:25:21 0 [Note] InnoDB: Starting shutdown...
142018-09-17 13:25:21 0 [ERROR] Plugin 'InnoDB' init function returned error.
152018-09-17 13:25:21 0 [ERROR] Plugin 'InnoDB' registration as a STORAGE ENGINE failed.
162018-09-17 13:25:21 0 [Note] Plugin 'FEEDBACK' is disabled.
172018-09-17 13:25:21 0 [ERROR] Could not open mysql.plugin table. Some plugins may be not loaded
182018-09-17 13:25:21 0 [ERROR] Unknown/unsupported storage engine: InnoDB
192018-09-17 13:25:21 0 [ERROR] Aborting

這個問題很多人已經遇到了,github上有很多討論,比如這個( https://github.com/docker-library/mariadb/issues/38 )還有這個( https://github.com/laradock/laradock/issues/916 )等,解決方法是在啟動容器的時候加一條命令 mysqld --innodb-flush-method=fsync

最終在Windows Docker 可以正常運行的docker-compose.yml是:

 1version: "3"
 2services:
 3  mariadb:
 4    image: mariadb
 5    container_name: mariadb
 6    restart: always
 7    volumes:
 8      - ${DATA_DIR}:/var/lib/mysql
 9    ports:
10      - "3306:3306"
11    environment:
12      MYSQL_ROOT_PASSWORD: password
13      MYSQL_DATABASE: public
14    command: 'mysqld --innodb-flush-method=fsync'

希望官方能夠在這之後的版本中解決這個問題。