docker-compose with multiple databases

后端 未结 6 698
天涯浪人
天涯浪人 2020-12-25 10:51

I\'m trying to figure out how to implement docker using docker-compose.yml with 2 databases imported from sql dumps.

httpd:
    container_name: webserver
            


        
6条回答
  •  感情败类
    2020-12-25 11:29

    After struggling, 3 days found this Article to solve this issue saved my life

    File Structure

    Project
    ├── docker-compose.yml (File)
    ├── init (Directory)
    │   ├── 01.sql (File)
    

    then point init directory inside the volumes in the docker-compose.yml file as following

    volumes: 
      - ./init:/docker-entrypoint-initdb.d
    

    01.sql

    CREATE DATABASE IF NOT EXISTS `test`;
    GRANT ALL ON `test`.* TO 'user'@'%';
    

    docker-compose.yml

    version: '3.6'
        
    services: 
        # MySQL
        db:
            image: mysql
            command: --default-authentication-plugin=mysql_native_password
            restart: always
            environment:
                MYSQL_ROOT_PASSWORD: root
                MYSQL_DATABASE: mydb
                MYSQL_USER: user
                MYSQL_PASSWORD: user
    
            volumes: 
                - ./init:/docker-entrypoint-initdb.d
        
        adminer:
            image: adminer
            restart: always
            ports:
                - 8080:8080
    

提交回复
热议问题