Running Rancher with external MySQL Database

Hi All,

I have the following issue with rancher when I try to run it with an external database.

It seems that rancher is not able to connect the external mysql database, here is an extract from the log:

15:34:35.705 [main] ERROR i.c.p.a.sources.LazyJDBCSource - Failed to get connection to database, will retry for 5 minutes
org.apache.commons.dbcp.SQLNestedException: Cannot create PoolableConnectionFactory (Could not connect to address=(host=localhost)(port=3306)(type=master) : Connection refused)
at org.apache.commons.dbcp.BasicDataSource.createPoolableConnectionFactory(BasicDataSource.java:1549) ~[commons-dbcp-1.4.jar:1.4]
at org.apache.commons.dbcp.BasicDataSource.createDataSource(BasicDataSource.java:1388) ~[commons-dbcp-1.4.jar:1.4]
at org.apache.commons.dbcp.BasicDataSource.getConnection(BasicDataSource.java:1044) ~[commons-dbcp-1.4.jar:1.4]
at io.cattle.platform.archaius.sources.LazyJDBCSource.checkInitial(LazyJDBCSource.java:50) [cattle-framework-archaius-0.5.0-SNAPSHOT.jar:na]
at io.cattle.platform.archaius.sources.LazyJDBCSource.poll(LazyJDBCSource.java:34) [cattle-framework-archaius-0.5.0-SNAPSHOT.jar:na]
at com.netflix.config.AbstractPollingScheduler$1.run(AbstractPollingScheduler.java:163) [archaius-core-0.5.14.jar:na]
at io.cattle.platform.archaius.polling.RefreshableFixedDelayPollingScheduler.refresh(RefreshableFixedDelayPollingScheduler.java:34) [cattle-framework-archaius-0.5.0-SNAPSHOT.jar:na]
at io.cattle.platform.archaius.startup.ArchaiusStartup.load(ArchaiusStartup.java:91) [cattle-iaas-archaius-management-0.5.0-SNAPSHOT.jar:na]
at io.cattle.platform.archaius.startup.ArchaiusStartup.start(ArchaiusStartup.java:68) [cattle-iaas-archaius-management-0.5.0-SNAPSHOT.jar:na]
at io.cattle.platform.extension.spring.BackgroundStart.run(BackgroundStart.java:63) [cattle-framework-extension-spring-0.5.0-SNAPSHOT.jar:na]
at org.apache.cloudstack.spring.module.model.impl.DefaultModuleDefinitionSet$1.with(DefaultModuleDefinitionSet.java:139) [cattle-framework-spring-module-0.5.0-SNAPSHOT.jar:na]
at org.apache.cloudstack.spring.module.model.impl.DefaultModuleDefinitionSet.withModule(DefaultModuleDefinitionSet.java:348) [cattle-framework-spring-module-0.5.0-SNAPSHOT.jar:na]
at org.apache.cloudstack.spring.module.model.impl.DefaultModuleDefinitionSet.withModule(DefaultModuleDefinitionSet.java:358) [cattle-framework-spring-module-0.5.0-SNAPSHOT.jar:na]
at org.apache.cloudstack.spring.module.model.impl.DefaultModuleDefinitionSet.withModule(DefaultModuleDefinitionSet.java:333) [cattle-framework-spring-module-0.5.0-SNAPSHOT.jar:na]
at org.apache.cloudstack.spring.module.model.impl.DefaultModuleDefinitionSet.runHookInContexts(DefaultModuleDefinitionSet.java:131) [cattle-framework-spring-module-0.5.0-SNAPSHOT.jar:na]
at org.apache.cloudstack.spring.module.model.impl.DefaultModuleDefinitionSet.startContexts(DefaultModuleDefinitionSet.java:123) [cattle-framework-spring-module-0.5.0-SNAPSHOT.jar:na]
at org.apache.cloudstack.spring.module.model.impl.DefaultModuleDefinitionSet.load(DefaultModuleDefinitionSet.java:100) [cattle-framework-spring-module-0.5.0-SNAPSHOT.jar:na]
at org.apache.cloudstack.spring.module.factory.ModuleBasedContextFactory.loadModules(ModuleBasedContextFactory.java:37) [cattle-framework-spring-module-0.5.0-SNAPSHOT.jar:na]
at org.apache.cloudstack.spring.module.factory.CloudStackSpringContext.init(CloudStackSpringContext.java:75) [cattle-framework-spring-module-0.5.0-SNAPSHOT.jar:na]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.7.0_95]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) ~[na:1.7.0_95]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.7.0_95]
at java.lang.reflect.Method.invoke(Method.java:606) ~[na:1.7.0_95]

This is the command I’m using to start the container:

sudo docker run -d --restart=always -p 8080:8080
-e CATTLE_DB_CATTLE_MYSQL_HOST=localhost
-e CATTLE_DB_CATTLE_MYSQL_PORT=3306
-e CATTLE_DB_CATTLE_MYSQL_NAME=cattle
-e CATTLE_DB_CATTLE_USERNAME=cattle
-e CATTLE_DB_CATTLE_PASSWORD=cattle
rancher/server:v1.1.0-dev4

I created the database with the following command:

CREATE DATABASE IF NOT EXISTS cattle COLLATE = ‘utf8_general_ci’ CHARACTER SET = ‘utf8’;
GRANT ALL ON cattle.* TO ‘cattle’@’%’ IDENTIFIED BY ‘cattle’;
GRANT ALL ON cattle.* TO ‘cattle’@‘localhost’ IDENTIFIED BY ‘cattle’;

It is possible to me to connect the mysql database from internal and an external host:

ubuntu:~$ mysql -h 172.28.50.150 -ucattle -p cattle
Enter password:
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 48
Server version: 10.0.25-MariaDB-1~trusty mariadb.org binary distribution
Copyright © 2000, 2016, Oracle, MariaDB Corporation Ab and others.
Type ‘help;’ or ‘\h’ for help. Type ‘\c’ to clear the current input statement.
MariaDB [cattle]>

I also tried to start rancher after I inserted the sql dump file from rancher but all results in the error message shown above.

Any suggestions what is causing this issue ?

Best regards, Thomas

localhost means the server container when resolved from inside it… You need to use a name or IP that will be accessible from inside the container.

I Have the same Error but I Try this config :

sudo docker run -d --restart=always -p 8080:8080 \
-e CATTLE_DB_CATTLE_MYSQL_HOST=172.17.0.1
-e CATTLE_DB_CATTLE_MYSQL_PORT=3306
-e CATTLE_DB_CATTLE_MYSQL_NAME=cattle
-e CATTLE_DB_CATTLE_USERNAME=cattle
-e CATTLE_DB_CATTLE_PASSWORD=qwerty
rancher/server:stable

I try to connect to mysql with this user, it’s correct. The machine ping without problem the 172.17.0.1 IP. Where is the problem ? My Rancher version is the 1.0.2

Hi, thanks for the tip with the external ip instead of localhost!

@throrin: Whats the output from “docker logs -f xxxxxxxx” ?
Is your mysql server listening on external ip addresses ?

Haha I miss to comment the bind to 127.0.0.1. Without is fine