docker群中使用的两个应用程序

我有两个应用程序(webapp和mysql)
在群的覆盖(如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: 

我创build名为mfnw的覆盖

我的webapp使用“jdbc:mysql:// mysql:3306 / msgflow?autoReconnect = true&failOverReadOnly = false&useUnicode = true&characterEncoding = utf-8”来连接mysql。

但它抛出了错误“com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException:无法创build连接到数据库服务器。试图重新连接3次。放弃。

当我使用一个主机,它的工作。 它只发生在两个主机上,我不是为什么?

原谅我的英语!