首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >挂载卷时无法运行mariadb

问挂载卷时无法运行mariadb
EN

Stack Overflow用户
提问于 2016-12-05 09:31:52
回答 1查看 2.6K关注 0票数 3

使用下面的docker-compose.yml文件

代码语言:javascript
复制
version: '2'

services:

  wordpress:
    image: wordpress
    ports:
      - 8080:80
    environment:
      WORDPRESS_DB_NAME: my_db
      WORDPRESS_DB_USER: root
      WORDPRESS_DB_PASSWORD: password
    volumes:
      - ./src:/var/www/html

  mysql:
    image: mariadb
    environment:
      MYSQL_ROOT_PASSWORD: password
    volumes:
      - ./data_dir:/var/lib/mysql

运行docker-compose up命令时,它会给我以下错误

代码语言:javascript
复制
Starting wp_mysql_1
Starting wp_wordpress_1
Attaching to wp_mysql_1, wp_wordpress_1
wordpress_1  |
wordpress_1  | Warning: mysqli::mysqli(): (HY000/2002): Connection refused in - on line 19
wordpress_1  |
wordpress_1  | MySQL Connection Error: (2002) Connection refused
mysql_1      | 2016-11-28 15:47:02 139858949081024 [Note] mysqld (mysqld 10.1.19-MariaDB-1~jessie) starting as process 1
 ...
mysql_1      | 2016-11-28 15:47:03 139858949081024 [Note] InnoDB: Using mutexes to ref count buffer pool pages
mysql_1      | 2016-11-28 15:47:03 139858949081024 [Note] InnoDB: The InnoDB memory heap is disabled
mysql_1      | 2016-11-28 15:47:03 139858949081024 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
mysql_1      | 2016-11-28 15:47:03 139858949081024 [Note] InnoDB: GCC builtin __atomic_thread_fence() is used for memory
 barrier
mysql_1      | 2016-11-28 15:47:03 139858949081024 [Note] InnoDB: Compressed tables use zlib 1.2.8
mysql_1      | 2016-11-28 15:47:03 139858949081024 [Note] InnoDB: Using Linux native AIO
mysql_1      | 2016-11-28 15:47:03 139858949081024 [Note] InnoDB: Using SSE crc32 instructions
mysql_1      | 2016-11-28 15:47:03 139858949081024 [Note] InnoDB: Initializing buffer pool, size = 256.0M
mysql_1      | 2016-11-28 15:47:03 139858949081024 [Note] InnoDB: Completed initialization of buffer pool
mysql_1      | 2016-11-28 15:47:03 139858949081024 [ERROR] InnoDB: auto-extending data file ./ibdata1 is of a different
size 0 pages (rounded down to MB) than specified in the .cnf file: initial 768 pages, max 0 (relevant if non-zero) pages
!
mysql_1      | 2016-11-28 15:47:03 139858949081024 [ERROR] InnoDB: Could not open or create the system tablespace. If yo
u tried to add new data files to the system tablespace, and it failed here, you should now edit innodb_data_file_path in
 my.cnf back to what it was, and remove the new ibdata files InnoDB created in this failed attempt. InnoDB only wrote th
ose files full of zeros, but did not yet use them in any way. But be careful: do not remove old data files which contain
 your precious data!
mysql_1      | 2016-11-28 15:47:03 139858949081024 [ERROR] Plugin 'InnoDB' init function returned error.
mysql_1      | 2016-11-28 15:47:03 139858949081024 [ERROR] Plugin 'InnoDB' registration as a STORAGE ENGINE failed.
mysql_1      | 2016-11-28 15:47:03 139858949081024 [Note] Plugin 'FEEDBACK' is disabled.
mysql_1      | 2016-11-28 15:47:03 139858949081024 [ERROR] Could not open mysql.plugin table. Some plugins may be not lo
aded
mysql_1      | 2016-11-28 15:47:03 139858949081024 [ERROR] Unknown/unsupported storage engine: InnoDB
mysql_1      | 2016-11-28 15:47:03 139858949081024 [ERROR] Aborting
mysql_1      |
wp_mysql_1 exited with code 1
wordpress_1  |
wordpress_1  | Warning: mysqli::mysqli(): php_network_getaddresses: getaddrinfo failed: Name or service not known in - o
n line 19
wordpress_1  |
wordpress_1  | Warning: mysqli::mysqli(): (HY000/2002): php_network_getaddresses: getaddrinfo failed: Name or service no
t known in - on line 19
wordpress_1  |
wordpress_1  | MySQL Connection Error: (2002) php_network_getaddresses: getaddrinfo failed: Name or service not known

但是如果我从mysql映像中删除了卷,那么它就能正常工作了!我如何挂载卷,因为我需要数据被持久化。

EN

回答 1

Stack Overflow用户

发布于 2019-07-16 15:37:01

这实际上是MariaDB的一个问题。您不能使用Docker将用于MariaDB的文件夹挂载到主机上,因为它将共享文件/文件夹权限显示给数据库容器,使之成为只有root才能写的根用户。解决方案是使用坞-组成命名卷。如码头文件所述:

Docker为容器在主机中存储文件提供了两个选项,这样即使在容器停止后,文件也会被持久化:卷和绑定挂载。如果在Linux上运行Docker,也可以使用tmpfs挂载。

您尝试使用的是绑定挂载,它不适用于MariaDB。所以我们可以用码头容量来做这个。

创建卷时,它存储在Docker主机上的目录中。当您将卷挂载到容器中时,这个目录就是安装到容器中的目录。这与绑定挂载的工作方式类似,只是卷由Docker管理,并且与主机的核心功能隔离。卷存储在由docker管理的主机文件系统的一部分中(/var/lib/docker/卷/在Linux上)。因此,请将您的停靠-撰写文件更改为:-

代码语言:javascript
复制
version: '2'

services:

      wordpress:
         image: wordpress
         ports:
           - 8080:80
         environment:
           WORDPRESS_DB_NAME: my_db
           WORDPRESS_DB_USER: root
           WORDPRESS_DB_PASSWORD: password
         volumes:
           - ./src:/var/www/html

       mysql:
         image: mariadb
         environment:
           MYSQL_ROOT_PASSWORD: password
         volumes:
           - db_data:/var/lib/mysql
volumes:
   db_data:

也就是说,在mysql服务下使用一个命名卷,并在顶级卷键中声明它。这将告诉创建一个Docker卷,并且您的MariaDB数据在主机上的/var/lib/docker/卷/_db_ data /_data目录中被备份/持久化。

此外,在运行了docker-compose命令之后,如果您执行了docker卷ls,那么您可以看到docker创建的卷。

票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/40971034

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档