source

볼륨을 마운트할 때 mariadb를 실행할 수 없습니다.

factcode 2022. 10. 27. 23:00
반응형

볼륨을 마운트할 때 mariadb를 실행할 수 없습니다.

다음 docker-compose.yml 파일 사용

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특공대, 다음 오류가 발생합니다.

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 이미지에서 볼륨을 삭제하면 정상적으로 동작합니다!데이터를 유지해야 하는데 볼륨을 마운트하려면 어떻게 해야 합니까?

MariaDB의 문제입니다.공유 파일/폴더 사용 권한을 데이터베이스 컨테이너에 루트별로만 쓰기 가능한 루트 소유로 표시하므로 도커를 사용하여 호스트에 MariaDB용 폴더를 마운트할 수 없습니다.해결 방법은 도커 구성 명명된 볼륨을 사용하는 것입니다.도커 매뉴얼에 기재되어 있는 바와 같이:
Docker에는 컨테이너가 중지된 후에도 파일이 유지되도록 컨테이너가 호스트 시스템에 파일을 저장하는 두 가지 옵션(볼륨과 바인딩 마운트)이 있습니다.Linux에서 Docker를 실행하는 경우 tmpfs 마운트를 사용할 수도 있습니다.

사용하려고 하는 것은 MariaDB에서는 동작하지 않는 바인드 마운트입니다.그래서 도커볼륨을 사용할 수 있습니다.

볼륨을 생성하면 볼륨이 도커 호스트의 디렉토리에 저장됩니다.볼륨을 컨테이너에 마운트하면 이 디렉토리가 컨테이너에 마운트됩니다.볼륨이 도커에 의해 관리되고 호스트 시스템의 핵심 기능에서 분리된다는 점을 제외하면 바인드 마운트의 작동 방식과 유사합니다.볼륨은 Docker(Linux의 경우 /var/lib/docker/volumes/)에 의해 관리되는 호스트 파일 시스템의 일부에 저장됩니다.따라서 도커 컴포지트 파일을 다음과 같이 변경합니다.

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 관리 볼륨을 생성하도록 지시하고 MariaDB 데이터는 호스트 시스템의 /var/lib/docker/volumes/_db_data/_data 디렉토리에 백업/지속됩니다.

또한 docker-compose up 명령을 실행한 후 docker volume ls를 실행하면 docker-compose created 볼륨을 볼 수 있습니다.

언급URL : https://stackoverflow.com/questions/40971034/unable-to-run-mariadb-when-mount-volume

반응형