我试图弄清楚如何使用docker-compose.yml和2个从sql dump导入的数据库来实现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 "<string>", line 3, in <module> File "compose/cli/main.py", line 63, in main AttributeError: 'ProjectError' object has no attribute 'msg' docker-compose returned -1
基本上,我试图在单个docker compose文件中获取整个堆栈设置,创建2个数据库并导入相应的sql转储。有人有什么建议吗?
就像其他可能对此有所了解的人的更新一样。
我通过删除解决了这个问题:
MYSQL_DATABASE: dbname
从 docker-compose.yml中 并将相关的create database语句直接添加到要传递到 docker-entrypoint- initdb.d 的sql文件中。
在此阶段,sql命令是在root用户下执行的,因此您还需要添加一条语句,以向要使用的数据库用户授予相关权限。