我有两个app(webapp和mysql)
在swarm的叠加(如https://blog.docker.com/2015/11/docker-multi-host-networking-ga/)中,我使用docker-compose.yml,如下所示:
version: '2'
services:
web:
image: mywebapp
ports:
- "8088:8080"
environment:
- "constraint:node==swl-demo0"
networks:
- mfnw
depends_on:
- mysql
mysql:
image: mysql:5.7.10
command: mysql -uroot -proot < /docker-entrypoint-initdb.d/init.sql
restart: always
environment:
- MYSQL_ROOT_PASSWORD=root
- MYSQL_DATABASE=msgflow
- MYSQL_USER=root
- MYSQL_PASSWORD=root
- "constraint:node==swl-demo1"
volumes:
- ./mysql-config/:/etc/mysql/conf.d:ro
- ./init.sql:/docker-entrypoint-initdb.d/init.sql
- /srv/docker/msgflow/mysql:/var/lib/mysql
ports:
- "3306:3306"
networks:
- mfnw
container_name: mysql
networks:
mfnw:
我创建了名为mfnw的叠加。
我的webapp使用&#34; jdbc:mysql:// mysql:3306 / msgflow?autoReconnect = true&amp; failOverReadOnly = false&amp; useUnicode = true&amp; characterEncoding = utf-8&#34;连接mysql。
但它抛出了错误&#34; com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException:无法创建与数据库服务器的连接。尝试重新连接3次。放弃。&#34;
当我使用一台主机时,它可以工作。它只发生在两个主持人身上,我不知道为什么?
原谅我的英语!