I'm traying to deploy a microserivice and a flyway service with Docker Compose in Ubuntu. The docker-compose.yml looks like this:
version: '2'
services:
mysqldb:
image: mysql:5.6.26
environment:
MYSQL_USER: user
MYSQL_PASSWORD: password
MYSQL_ROOT_PASSWORD: password
MYSQL_DATABASE: base
ports:
- "3306:3306"
flyway-service-i:
image: mialk/flyway-service
volumes:
- "../resources/db/migration:/migrations/ro"
depends_on:
- mysqldb
links:
- mysqldb
command: migrate -url=jdbc:mysql://mysqldb:3306/base -user=user -password=password -baselineOnMigrate=true - locations='filesystem:/migrations'
service1:
image: my/service
ports:
- "8080:8080"
links:
- mysqldb
environment:
- SPRING_DATASOURCE_URL=jdbc:mysql://mysqldb:3306/base
- SPRING_DATASOURCE_USERNAME=user
- SPRING_DATASOURCE_PASSWORD=password
But when I run the command: sudo docker-compose up, I have this message:
flyway-service-i_1 | ERROR: Unable to obtain Jdbc connection from DataSource (jdbc:mysql://mysqldb:3306/base) for user 'user': Host '172.18.0.4' is not allowed to connect to this MySQL server
Each time that I run the command, I get a different host, e.g:
ERROR: Unable to obtain Jdbc connection from DataSource (jdbc:mysql://mysqldb:3306/base) for user 'user': Host '172.18.0.6' is not allowed to connect to this MySQL server
The data base was created in that way:
CREATE DATABASE base CHARACTER SET utf8 COLLATE utf8_bin;
GRANT ALL PRIVILEGES ON base.* To 'user'@'localhost';
The ifconfig command shows that Docker has the IP 172.17.0.1.
I don't know why flyway can't connect to the data base, and why the host changes en each call,can you help me please?
Thanks! :)
$ docker version
– Fabian