我有下面的docker-compose-yml:
version: '3.1'
services:
wordpress:
image: wordpress
restart: always
ports:
- 8080:80
environment:
WORDPRESS_DB_HOST: db
WORDPRESS_DB_USER: wp_user
WORDPRESS_DB_PASSWORD: password
WORDPRESS_DB_NAME: wp_db
volumes:
- ./wordpress:/var/www/html
networks:
- my_network
db:
image: mariadb:10.7.8
restart: always
environment:
MYSQL_DATABASE: wp_db
MYSQL_USER: wp_user
MYSQL_PASSWORD: password
MYSQL_ROOT_PASSWORD: password
MARIADB_MYSQL_LOCALHOST_USER: 1
MARIADB_MYSQL_LOCALHOST_GRANTS: "RELOAD, PROCESS, LOCK TABLES, BINLOG MONITOR"
volumes:
- ./data:/docker-entrypoint-initdb.d
- ./datadir:/var/lib/mysql
- backup:/backup
networks:
- my_network
volumes:
backup:
networks:
my_network:
driver: bridge
这样就可以正常工作了。站点正在运行并使用数据库。
当我运行命令时:
docker compose run db mariabackup --backup --target-dir=/backup
我得到了以下结果:
[00] 2023-03-18 16:32:15 Connecting to MariaDB server host: localhost, user: not set, password: not set, port: not set, socket: /run/mysqld/mysqld.sock
[00] 2023-03-18 16:32:15 Failed to connect to MariaDB server: Can't connect to local server through socket '/run/mysqld/mysqld.sock' (2 "No such file or directory").
我不知道为什么套接字被定义成这样,我想应该是'/var/run/mysqld/mysqld. sock'?
任何帮助感激不尽!
1条答案
按热度按时间6jjcrrmo1#
根据在容器中获取备份的documentation:
因为我们有一个套接字问题,如果你想使用
compose
,尝试在db服务中添加新的套接字卷:并将
some-mariadb-socket
添加到volumes
:试试看:
然后是
exec
而不是run
。