装入卷时无法运行mariadb [英] Unable to run mariadb when mount volume

查看:75
本文介绍了装入卷时无法运行mariadb的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用以下docker-compose.yml文件

Using the following docker-compose.yml file

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 Commande时,出现以下错误

when running docker-compose up commande,its giving me following error

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镜像中删除了卷,那么它可以正常工作!当我需要持久存储数据时,如何安装该卷.

but if I removed the volumes from mysql image, then it works fine! How can I mount the volume as I need data to be persisted.

推荐答案

这实际上是MariaDB的问题.您无法使用Docker将MariaDB的文件夹安装到主机,因为该文件夹以root身份提供对数据库容器的共享文件/文件夹权限,并且只能由root写入.解决方案是使用docker-compose命名卷.如Docker文档中所述:
Docker的容器有两个选项,可以在主机中存储文件,这样即使容器停止后文件也可以持久保存:卷和绑定挂载.如果您在Linux上运行Docker,也可以使用tmpfs挂载.

It's actually a problem with MariaDB. You cannot mount the folder for MariaDB to the host using Docker because it presents the shared files/folders permissions to the database container as root owned with writable only by root. The solution is to use docker-compose named volumes. As stated in docker documentation:
Docker has two options for containers to store files in the host machine, so that the files are persisted even after the container stops: volumes, and bind mounts. If you’re running Docker on Linux you can also use a tmpfs mount.

您要使用的绑定绑定不适用于MariaDB.因此,我们可以使用Docker卷.

What you are trying to use is the bind-mount which does not works with MariaDB. So we can use docker volume for that.

创建卷时,它存储在Docker主机上的目录中.将卷装入容器时,此目录就是装入容器的目录.这类似于绑定挂载的工作方式,除了卷由Docker管理并且与主机的核心功能隔离.卷存储在主机文件系统的一部分中,该文件系统由Docker管理(在Linux上为/var/lib/docker/volumes/).因此,将您的docker-compose文件更改为:-

When you create a volume, it is stored within a directory on the Docker host. When you mount the volume into a container, this directory is what is mounted into the container. This is similar to the way that bind mounts work, except that volumes are managed by Docker and are isolated from the core functionality of the host machine. Volumes are stored in a part of the host filesystem which is managed by Docker(/var/lib/docker/volumes/ on Linux). So change your docker-compose file as:-

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-compose创建Docker mananged卷,并且您的MariaDB数据将在主机上的/var/lib/docker/volumes/_db_data/_data目录中备份/持久化.

i.e. use a named volume under mysql service and declare it in top level volumes key. This will tell docker-compose to create a Docker mananged volume and your MariaDB data is backed up/persisted at /var/lib/docker/volumes/_db_data/_data directory on host machine.

还可以在运行docker-compose up命令后执行 码头工人卷ls 然后您可以看到docker-compose创建的卷.

Also after running docker-compose up command if you do docker volume ls then you can see docker-compose created volume.

这篇关于装入卷时无法运行mariadb的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆