gpt4 book ai didi

Docker 多个 MYSQL 容器

转载 作者:行者123 更新时间:2023-12-04 06:53:54 29 4
gpt4 key购买 nike

Docker 新手在这里。

我想要实现的是使用 docker compose 运行多个 MySQL 容器,以及一个 nginx、一个 PHP 和一个 PhpMyAdmin 容器。

这是我的 docker-compose.yml:

version: '3'
services:
server:
build:
context: ./
dockerfile: server.docker
volumes:
- ./:/var/www
ports:
- "8080:80"
links:
- app
app:
build:
context: ./
dockerfile: app.docker
volumes:
- ./:/var/www
links:
- db_callcenter
- db_forecast
- db_logistics
- db_products
- db_rm
- db_rma
- db_settings
- db_tasks
- db_users
db_callcenter:
image: mysql:5.7
environment:
- "MYSQL_ROOT_PASSWORD=secret"
- "MYSQL_DATABASE=prj_callcenter"
ports:
- "33061:3306"
volumes:
- mysql_bkp:/var/lib/mysql
db_forecast:
image: mysql:5.7
environment:
- "MYSQL_ROOT_PASSWORD=secret"
- "MYSQL_DATABASE=prj_forecast"
ports:
- "33062:3306"
volumes:
- mysql_bkp:/var/lib/mysql
db_logistics:
image: mysql:5.7
environment:
- "MYSQL_ROOT_PASSWORD=secret"
- "MYSQL_DATABASE=prj_logistics"
ports:
- "33063:3306"
volumes:
- mysql_bkp:/var/lib/mysql
db_products:
image: mysql:5.7
environment:
- "MYSQL_ROOT_PASSWORD=secret"
- "MYSQL_DATABASE=prj_products"
ports:
- "33064:3306"
volumes:
- mysql_bkp:/var/lib/mysql
db_rm:
image: mysql:5.7
environment:
- "MYSQL_ROOT_PASSWORD=secret"
- "MYSQL_DATABASE=prj_rm"
ports:
- "33065:3306"
volumes:
- mysql_bkp:/var/lib/mysql
db_rma:
image: mysql:5.7
environment:
- "MYSQL_ROOT_PASSWORD=secret"
- "MYSQL_DATABASE=prj_rma"
ports:
- "33066:3306"
volumes:
- mysql_bkp:/var/lib/mysql
db_settings:
image: mysql:5.7
environment:
- "MYSQL_ROOT_PASSWORD=secret"
- "MYSQL_DATABASE=prj_settings"
ports:
- "33067:3306"
volumes:
- mysql_bkp:/var/lib/mysql
db_tasks:
image: mysql:5.7
environment:
- "MYSQL_ROOT_PASSWORD=secret"
- "MYSQL_DATABASE=prj_tasks"
ports:
- "33068:3306"
volumes:
- mysql_bkp:/var/lib/mysql
db_users:
image: mysql:5.7
environment:
- "MYSQL_ROOT_PASSWORD=secret"
- "MYSQL_DATABASE=prj_users"
ports:
- "33069:3306"
volumes:
- mysql_bkp:/var/lib/mysql
pma:
image: phpmyadmin/phpmyadmin
environment:
- "PMA_USER=root"
- "PMA_PASSWORD=secret"
ports:
- "8001:80"
links:
- db_callcenter
- db_forecast
- db_logistics
- db_products
- db_rm
- db_rma
- db_settings
- db_tasks
- db_users
volumes:
mysql_bkp:

但是没有创建任何 MySQL 容器。当我运行 docker ps 时,我得到:
CONTAINER ID        IMAGE                   COMMAND                  CREATED              STATUS              PORTS                  NAMES
0228e9c8a267 phpmyadmin/phpmyadmin "/run.sh phpmyadmin" About a minute ago Up 30 seconds 0.0.0.0:8001->80/tcp prj_pma_1
e6c6b11905f1 prj_server "nginx -g 'daemon ..." 22 minutes ago Up 2 minutes 0.0.0.0:8080->80/tcp prj_server_1
2e7dd484c6e5 prj_app "docker-php-entryp..." 24 minutes ago Up 2 minutes 9000/tcp prj_app_1

更新:

docker 日志显示:
Unable to lock ./ibdata1 error: 11

要么
InnoDB: Unsupported redo log format.

我不知道我做错了什么,或者我应该如何开始调试。任何帮助将不胜感激。

最佳答案

您不能让多个 mysql 进程共享同一个数据目录。在您的撰写文件中,每个数据库容器都使用相同的 mysql_bkp体积。您需要为每个容器创建一个卷,或者将 mysql 配置为使用唯一的子目录 /var/lib/mysql用于存储数据。

如果您只是删除 volumes:来自每个数据库服务的 key ,它们都将获得一个唯一的匿名卷(因为这就是 mysql 图像的配置方式)。

或者,您可以为每个服务声明并挂载一个单独的卷:

services:
db_logistics:
image: mysql:5.7
volumes:
- mysql_bkp_logistics:/var/lib/mysql
db_products:
image: mysql:5.7
volumes:
- mysql_bkp_products:/var/lib/mysql

volumes:
mysql_bkp_logistics:
mysql_bkp_products:

等等。

关于Docker 多个 MYSQL 容器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46938303/

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