Docker Image unable to connect to DB

Hi. I am brand new to Librenms and have very little experience with dockers. So this question is pretty noobish.

For some reason my librenms container won’t connect to my local database.

I run the following

docker run -d -h librenmsdocker -p 80:80 -e DB_HOST=localhost -e DB_NAME=librenms -e DB_USER=librenms -e DB_PASSWORD=librenms123 -e BASE_URL=http://host.host.com -v /data/logs:/opt/librenms/logs -v /data/rrd:/opt/librenms/rrd --name librenms/librenms:latest

The logs however say the following…

Waiting 30s for database to be ready…
ERROR: Failed to connect to database on localhost

I can connect to the local database instance with those credentials though…

mysql -u librenms -plibrenms123
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 108
Server version: 5.5.56-MariaDB MariaDB Server

Any idea why this isn’t working? I don’t see it even trying to connect to the mysql server.

localhost != localhost, you need to specify DB_HOST by ip or hostname

Same problem…

Initializing LibreNMS files / folders…
Setting LibreNMS configuration…
Fixing permissions…
Checking additional Monitoring plugins…
Waiting 30s for database to be ready…
ERROR: Failed to connect to database on 127.0.0.1

@Brian_Gibson the MySQL database is not at 127.0.0.1 or localhost. Localhost does not go to the host machine, it stays inside the container.

Its better to use docker compose and then you just put the service-name in. Docker will route it to the correct container.

or for example in this docker compose file “db” you can use as a hostname which would always route to the correct container IP as it has been linked to the service-name. https://github.com/jarischaefer/docker-librenms/blob/master/docker-compose.yml

Thanks for the help guys. I figured out my problem. It was a mysql problem. It didn’t like that the user was coming from the docker0 ip address so it kept denying access. Normally I would have spotted that pretty quickly with a packet capture but I am still getting the hang of dockers.

Chas,

I actually tried to use docker compose but the version of docker compose I can download didn’t like the sample config that Jaris provided.

I’m excited to see what this product can do!!