jarischaefer / docker-librenms

Docker image for LibreNMS
MIT License
115 stars 37 forks source link

Default installation won't connect to linked mysql container #81

Closed vowywowy closed 6 years ago

vowywowy commented 6 years ago

I'm trying to demo this out in lab environment but I can't get it to work following the docs/walkthrough. When I browse to the librenms web interface I get:

Error connecting to database.
Access denied for user 'librenms'@'172.17.0.3' (using password: YES)

Where 172.17.0.3 is the ip for the librenms container, not the mysql container.

Since I'm just trying to demo before deploying to production I haven't done anything exotic. These are all the commands I've run:

# creating the mysql container
docker run \
        --name librenms-mysql \
        -d \
        -e MYSQL_ROOT_PASSWORD=P@ssw0rd \
        -p 127.0.0.1:3306:3306 \
        -v /my/persistent/directory/mysql:/var/lib/mysql \
        mysql:latest --sql-mode=""

# mysql database as per the librenms docs
mysql --host=127.0.0.1 --user=root -pP@ssw0rd -e "CREATE DATABASE librenms CHARACTER SET utf8 COLLATE utf8_unicode_ci;"
mysql --host=127.0.0.1 --user=root -pP@ssw0rd -e "CREATE USER 'librenms'@'localhost' IDENTIFIED BY 'P@ssw0rd';"
mysql --host=127.0.0.1 --user=root -pP@ssw0rd -e "GRANT ALL PRIVILEGES ON librenms.* TO 'librenms'@'localhost';"
mysql --host=127.0.0.1 --user=root -pP@ssw0rd -e "FLUSH PRIVILEGES;"

# creating the librenms container
docker run \
        -d \
        -h librenms \
        -p 80:80 \
        -e DB_HOST=db \
        -e DB_NAME=librenms \
        -e DB_USER=librenms \
        -e DB_PASS=P@ssw0rd \
        -e BASE_URL=http://localhost \
        --link librenms-mysql:db \
        -v /data/logs:/opt/librenms/logs \
        -v /data/rrd:/opt/librenms/rrd \
        --name librenms \
        jarischaefer/docker-librenms

The included P@ssw0rd isn't a real password so don't worry about me posting that.

My docker ps looks like this:

root@photon-2f4de1f20a6e [ ~ ]# docker ps
CONTAINER ID        IMAGE                          COMMAND                  CREATED             STATUS              PORTS                                 NAMES
aaf35d473365        jarischaefer/docker-librenms   "/sbin/my_init"          8 minutes ago       Up 8 minutes        0.0.0.0:80->80/tcp, 443/tcp           librenms
5122eba16ad7        mysql:latest                   "docker-entrypoint..."   11 minutes ago      Up 11 minutes       127.0.0.1:3306->3306/tcp, 33060/tcp   librenms-mysql

I'm not sure where I've gone wrong so any help I could get on this would be greatly appreciated.

Thanks.

EDIT: Just some more info on this. As per the nginx logs:

Stack trace:
#0 /opt/librenms/app/Providers/AppServiceProvider.php(33): dbConnect('librenms-mysql', 'librenms', 'P@ssw0rd', 'librenms', 3306, NULL)
#1 [internal function]: App\Providers\AppServiceProvider->boot()
#2 /opt/librenms/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(29): call_user_func_array(Array, Array)
#3 /opt/librenms/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(87): Illuminate\Container\BoundMethod::Illuminate\Container\{closure}()
#4 /opt/librenms/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(31): Illuminate\Container\BoundMethod::callBoundMethod(Object(Illuminate\Foundation\Application), Array, Object(Closure))
#5 /opt/librenms/vendor/laravel/framework/src/Illuminate/Container/Container.php(539): Illuminate\Container\BoundM" while reading response header from upstream, client: 192.168.1.145, server: _, request: "GET / HTTP/1.1", upstream: "fastcgi://unix:/var/run/php/php7.2-fpm.sock:", host: "192.168.1.161"
2018/08/29 15:57:01 [error] 49#49: *18 FastCGI sent in stderr: "PHP message: [2018-08-29 15:57:01] production.ERROR: LibreNMS\Exceptions\DatabaseConnectException: Access denied for user 'librenms'@'172.18.0.3' (using password: YES) in /opt/librenms/includes/dbFacile.php:86

0 shows that dbConnect is being passed the right args (librenms-mysql, librenms, P@ssw0rd, librenms) but #5 indicates something is changing the database to the librenms container's ip.

jarischaefer commented 6 years ago

Please note:

It is a common trap.

vowywowy commented 6 years ago

Wow thanks, totally skipped right by that one. Got it running with that change.