gpt4 book ai didi

docker - 使用数据量的MariaDB Docker容器-错误2002,无法通过套接字连接

转载 作者:行者123 更新时间:2023-12-02 20:00:19 24 4
gpt4 key购买 nike

我已经将MariaDB安装在Docker容器中,并且工作正常。我想将数据目录移动到外部卷,以将数据库与容器生命周期分开。我遵循了here的指示,但是当我现在尝试连接到引擎时,我得到了:

ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/www/databases/mysqld/mysqld.sock' (2)

“/ var / www /”是外部卷的安装点。我想知道这是否是权限问题,因此我将MariaDB容器中数据库文件夹的所有者设置为“myqsl”,即MySQL帐户的名称。
drwxr-xr-x 3 mysql mysql 4096 Jan 15 16:38 databases
drwxr-xr-x 3 1000 1000 4096 Jan 15 13:59 files
drwxr-xr-x 2 1000 1000 4096 Jan 15 15:20 html
drwxr-xr-x 3 1000 1000 4096 Jan 15 13:59 src

注意:在主机文件系统中,所有者列出为999:docker。这有关系吗?
drwxr-xr-x 3       999 docker    4096 Jan 15 16:38 databases

我缺少什么允许我将数据库存储在卷中?

这是我的/etc/MySQL/my.cnf文件(定义各种文件夹的位)的部分转储:
[client]
port = 3306
#socket = /var/run/mysqld/mysqld.sock
socket = /var/www/databases/mysqld/mysqld.sock

# Here is entries for some specific programs
# The following values assume you have at least 32M ram

# This was formally known as [safe_mysqld]. Both versions are currently parsed.
[mysqld_safe]
#socket = /var/run/mysqld/mysqld.sock
socket = /var/www/databases/mysqld/mysqld.sock
nice = 0

[mysqld]
#
# * Basic Settings
#
#user = mysql
pid-file = /var/run/mysqld/mysqld.pid
#socket = /var/run/mysqld/mysqld.sock
socket = /var/www/databases/mysqld/mysqld.sock
port = 3306
basedir = /usr
#datadir = /var/lib/mysql
datadir = /var/www/databases
tmpdir = /tmp
lc_messages_dir = /usr/share/mysql
lc_messages = en_US
skip-external-locking

docker-compose.yml:

这是我的yml文件的内容。我是这个东西的初学者,所以可能充满了空洞。请客气。 :)
version: '3.2'
volumes:
mwApache2Data:
external: true
webContent:
external: true

networks:
frontend:
backend:

services:
php:
build: './php7.1/'
image: php7.1.26-fpm:1.0
restart: always
container_name: php7.1.26-fpm
networks:
- backend
# volumes:
# - mwApache2Data:/app
web:
build: ./apache2/
image: apache2:1.0
restart: always
container_name: AOW_apache2Server
depends_on:
- php
- mariadb
networks:
- frontend
- backend
expose:
- "80"
- "81"
- "443"
- "8083"
ports:
- "80:80"
- "81:81"
- "443:443"
- "8083:8083"
volumes:
- mwApache2Data:/app
- webContent:/var/www
mariadb:
build: ./mariaDB/
image: mariadb_10.4.0
container_name: mariaDB_10.4.0
restart: always
networks:
- backend
environment:
- MYSQL_DATABASE=lg_wiki_db
- MYSQL_USER=wikiuser
- MYSQL_PASSWORD=****
- MYSQL_ROOT_PASSWORD=****
volumes:
- webContent:/var/www
mediawiki:
image: mediawiki:1.31.1
container_name: mediawiki_1.31.1
restart: always
depends_on:
- web
networks:
- backend
# ports:
# - 8080:80
links:
- mariadb
volumes:
- webContent:/var/www/
# After initial setup, download LocalSettings.php to the same directory as
# this yaml and uncomment the following line and use compose to restart
# the mediawiki service
# - ./LocalSettings.php:/var/www/html/LocalSettings.php
phpmyadmin:
image: phpmyadmin/phpmyadmin
container_name: phpmyadmin
restart: always
depends_on:
- web
expose:
- 80
networks:
- frontend
- backend
ports:
- 8080:80
links:
- mariadb

最佳答案

您是否尝试过在docker-compose中安装卷/ var / www / databases?
在链接了示例之后,我建议:

  ...
mysql:
image: mysql:5.6.40
networks:
- backend
environment:
- MYSQL_ROOT_PASSWORD=rootpassword
volumes:
- ./your_persistent_db_data_dir:/var/www/databases

要考虑的另一件事是网络问题。在这种情况下,我应该尝试在所有人之间共享docker网络,将 network_mode: host添加到要在它们之间进行通信的每个服务中。

最后,如果这些都不起作用,我尝试尝试的另一件事是尝试在主机中安装MariaDB,并将文件/var/www/databases/mysqld/mysqld.sock挂载为卷。我不建议这样做,也不是很优雅,此外,我的目标是将DB存储在外部具有持久性数据的docker中。

关于docker - 使用数据量的MariaDB Docker容器-错误2002,无法通过套接字连接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54215309/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com