Docker多个MYSQL容器

时间:2017-10-25 17:10:39

标签: docker docker-compose

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 logs显示:

Unable to lock ./ibdata1 error: 11

InnoDB: Unsupported redo log format.

我不知道我做错了什么,或者我应该如何开始调试。任何帮助都会受到赞赏。

1 个答案:

答案 0 :(得分:7)

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

如果您只是从每个数据库服务中删除volumes:密钥,它们都将获得一个唯一的匿名卷(因为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: