docker-compose with multiple databases

前端之家收集整理的这篇文章主要介绍了docker-compose with multiple databases前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

我试图弄清楚如何使用docker-compose.yml和从sql转储导入的2个数据库来实现docker.

httpd:
    container_name: webserver
    build: ./webserver/
    ports:
        - 80:80
    links:
        - MysqL
        - MysqL2
    volumes_from:
        - app

MysqL:
    container_name: sqlserver
    image: MysqL:latest
    ports:
        - 3306:3306
    volumes:
        - ./sqlserver:/docker-entrypoint-initdb.d
    environment:
        MysqL_ROOT_PASSWORD: root
        MysqL_DATABASE: dbname1
        MysqL_USER: dbuser
        MysqL_PASSWORD: dbpass

MysqL2:
    extends: MysqL
    container_name: sqlserver2
    environment:
        MysqL_ROOT_PASSWORD: root
        MysqL_DATABASE: dbname2
        MysqL_USER: dbuser
        MysqL_PASSWORD: dbpass

app:
    container_name: webdata
    image: PHP:latest
    volumes:
        - ../PHP:/var/www/html
    command: "true"

以上返回以下内容

Kronos:mybuild avanche$./run.sh 
Creating sqlserver
Creating webdata
Creating sqlserver2

ERROR: for MysqL2  driver Failed programming external connectivity on endpoint sqlserver2 (6cae3dfe7997d3787a8d59a95c1b5164f7431041c1394128c14e5ae8efe647a8): Bind for 0.0.0.0:3306 Failed: port is already allocated
Traceback (most recent call last):
  File "

基本上,我正在尝试将整个堆栈设置放在一个docker compose文件中,创建2个数据库并导入相应的sql转储.
有人有什么建议吗?

最佳答案
您正在尝试将两个数据库容器绑定到同一个端口 – 3306.这基本上是不可能的.
您需要更改其中一个数据库的端口映射,例如MysqL保留3306:3306,MysqL2应使用3307:3306.
原文链接:https://www.f2er.com/docker/436828.html

猜你在找的Docker相关文章