# Running Rancher with external MySQL Database

**URL:** <https://forums.suse.com/t/running-rancher-with-external-mysql-database/3062>\
**Category:** General\
**Created:** [June 8, 2016, 3:44pm UTC](https://forums.suse.com/t/running-rancher-with-external-mysql-database/3062 "2016-06-08T15:44:14Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Tom\_ger\_muc](https://avatars.discourse-cdn.com/v4/letter/t/c0e974/32.png) [@Tom\_ger\_muc](https://forums.suse.com/u/Tom_ger_muc)\
**Post date:** [June 8, 2016, 3:44pm UTC](https://forums.suse.com/t/running-rancher-with-external-mysql-database/3062/1 "2016-06-08T15:44:14Z")

</div>

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](http://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

---

<div class="post-metadata">

**Author:** ![vincent](https://sea2.discourse-cdn.com/flex022/user_avatar/forums.suse.com/vincent/32/7156_2.png) [@vincent](https://forums.suse.com/u/vincent)\
**Post date:** [June 8, 2016, 6:26pm UTC](https://forums.suse.com/t/running-rancher-with-external-mysql-database/3062/2 "2016-06-08T18:26:17Z")

</div>

`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.

---

<div class="post-metadata">

**Author:** ![throrin19](https://sea2.discourse-cdn.com/flex022/user_avatar/forums.suse.com/throrin19/32/1226_2.png) [@throrin19](https://forums.suse.com/u/throrin19)\
**Post date:** [June 13, 2016, 7:21am UTC](https://forums.suse.com/t/running-rancher-with-external-mysql-database/3062/3 "2016-06-13T07:21:18Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Tom\_ger\_muc](https://avatars.discourse-cdn.com/v4/letter/t/c0e974/32.png) [@Tom\_ger\_muc](https://forums.suse.com/u/Tom_ger_muc)\
**Post date:** [June 13, 2016, 7:48am UTC](https://forums.suse.com/t/running-rancher-with-external-mysql-database/3062/4 "2016-06-13T07:48:57Z")

</div>

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 ?

---

<div class="post-metadata">

**Author:** ![throrin19](https://sea2.discourse-cdn.com/flex022/user_avatar/forums.suse.com/throrin19/32/1226_2.png) [@throrin19](https://forums.suse.com/u/throrin19)\
**Post date:** [June 13, 2016, 8:24am UTC](https://forums.suse.com/t/running-rancher-with-external-mysql-database/3062/5 "2016-06-13T08:24:45Z")

</div>

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