Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Docker multiple MYSQL containers

Docker newbie here.

What I'm trying to achieve is to run multiple MySQL containers with docker compose, in addition to an nginx, a PHP and a PhpMyAdmin container.

This is my 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:

But none of the MySQL containers are created. When I run docker ps I get:

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

UPDATE:

docker logs shows:

Unable to lock ./ibdata1 error: 11

or

InnoDB: Unsupported redo log format.

I don't know what I'm doing wrong, or how I should start debugging. Any help would be mostly appreciated.

like image 539
Illes Peter Avatar asked Oct 25 '17 17:10

Illes Peter


1 Answers

You can't have multiple mysql processes sharing the same data directory. In your compose file, every database container is using the same mysql_bkp volume. You will need to either create one volume per container, or configure mysql to use a unique subdirectory of /var/lib/mysql for storing data.

If you simply remove the volumes: key from each database service, they will all get a unique anonymous volume (because that's how the mysql image is configured).

Alternatively, you can declare and mount a separate volume for each service:

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:

Etc.

like image 153
larsks Avatar answered Oct 25 '22 22:10

larsks