Problem:Docker container could not access the MariaDB - ERROR 2002 (HY000): Can't connect to MySQL server

Problem

The Docker container cannot access the MariaDB on the host, so in our case it was not possible to access the Bluespice Media wiki page.

Backtrace:

#0 /var/www/bluespice/includes/libs/rdbms/loadbalancer/LoadBalancer.php(1140): Wikimedia\Rdbms\Database->reportConnectionError('Connection refu...')
#1 /var/www/bluespice/includes/libs/rdbms/loadbalancer/LoadBalancer.php(750): Wikimedia\Rdbms\LoadBalancer->reportConnectionError()
#2 /var/www/bluespice/includes/GlobalFunctions.php(2813): Wikimedia\Rdbms\LoadBalancer->getConnection(0, Array, false)
#3 /var/www/bluespice/includes/user/User.php(534): wfGetDB(-1)
#4 /var/www/bluespice/includes/libs/objectcache/WANObjectCache.php(1095): User->{closure}(false, 3600, Array, NULL)
#5 /var/www/bluespice/includes/libs/objectcache/WANObjectCache.php(1243): WANObjectCache->{closure}(false, 3600, Array, NULL)
#6 /var/www/bluespice/includes/libs/objectcache/WANObjectCache.php(1078): WANObjectCache->doGetWithSetCallback('global:user:id:...', 3600, Object(Closure), Array, NULL)
#7 /var/www/bluespice/includes/user/User.php(561): WANObjectCache->getWithSetCallback('global:user:id:...', 3600, Object(Closure), Array)
#8 /var/www/bluespice/includes/user/User.php(482): User->loadFromCache()
#9 /var/www/bluespice/includes/user/User.php(420): User->loadFromId(0)
#10 /var/www/bluespice/includes/session/UserInfo.php(88): User->load()
#11 /var/www/bluespice/includes/session/CookieSessionProvider.php(126): MediaWiki\Session\UserInfo::newFromId('1')
#12 /var/www/bluespice/includes/session/SessionManager.php(488): MediaWiki\Session\CookieSessionProvider->provideSessionInfo(Object(WebRequest))
#13 /var/www/bluespice/includes/session/SessionManager.php(191): MediaWiki\Session\SessionManager->getSessionInfoForRequest(Object(WebRequest))
#14 /var/www/bluespice/includes/WebRequest.php(736): MediaWiki\Session\SessionManager->getSessionForRequest(Object(WebRequest))
#15 /var/www/bluespice/includes/session/SessionManager.php(130): WebRequest->getSession()
#16 /var/www/bluespice/includes/Setup.php(847): MediaWiki\Session\SessionManager::getGlobalSession()
#17 /var/www/bluespice/includes/WebStart.php(88): require_once('/var/www/bluesp...')
#18 /var/www/bluespice/index.php(39): require('/var/www/bluesp...')
#19 {main}

Solution

By setting the port to MariaDB, the container was able to reconnect to the database. This made the Bluespice Media wiki site accessible again.

  1. ucr set security/packetfilter/tcp/3306/all=ACCEPT
  2. service univention-firewall restart
  3. systemctl restart docker.service
  4. univention-app restart bluespice

Investigation

The first idea was to check the status of the database itself, to see if it was up and running.

root@srv-wiki:/var/log# systemctl status mariadb
● mariadb.service - MariaDB 10.3.39 database server
   Loaded: loaded (/lib/systemd/system/mariadb.service; enabled; vendor preset: enabled)
  Drop-In: /lib/systemd/system/mariadb.service.d
           └─univention.conf
   Active: active (running) since Wed 2024-09-18 14:58:17 CEST; 27min ago
     Docs: man:mysqld(8)
           https://mariadb.com/kb/en/library/systemd/
  Process: 25980 ExecStartPre=/usr/bin/install -m 755 -o mysql -g root -d /var/run/mysqld (code=exited, status=0/SUCCESS)
  Process: 25981 ExecStartPre=/bin/sh -c systemctl unset-environment _WSREP_START_POSITION (code=exited, status=0/SUCCESS)
  Process: 25983 ExecStartPre=/bin/sh -c [ ! -e /usr/bin/galera_recovery ] && VAR= ||   VAR=`cd /usr/bin/..; /usr/bin/galera_recovery`; [ $? -eq 0 ]   && systemctl set-enviro
  Process: 26088 ExecStartPost=/bin/sh -c systemctl unset-environment _WSREP_START_POSITION (code=exited, status=0/SUCCESS)
  Process: 26090 ExecStartPost=/etc/mysql/debian-start (code=exited, status=0/SUCCESS)
 Main PID: 26057 (mysqld)
   Status: "Taking your SQL requests now..."
    Tasks: 34 (limit: 4915)
   Memory: 360.6M
   CGroup: /system.slice/mariadb.service
           └─26057 /usr/sbin/mysqld

Sep 18 14:58:16 srv-wiki systemd[1]: Starting MariaDB 10.3.39 database server...
Sep 18 14:58:17 srv-wiki systemd[1]: Started MariaDB 10.3.39 database server.

DB information is copied from the environment variables so that the MariaDB can be queried directly.

root@srv-wiki:/var/log# docker inspect 2de

root@srv-wiki:/var/log# mariadb -u bluespice -p bluespice
Enter password:
ERROR 1045 (28000): Access denied for user 'bluespice'@'localhost' (using password: YES)

I can’t access the DB server from the container?

root@srv-wiki:/var/log#docker exec -it 2de /bin/bash
root@blues-13288299:/# mariadb -h 172.17.42.1 -u bluespice -p bluespice
Enter password:
ERROR 2002 (HY000): Can't connect to MySQL server on '172.17.42.1' (115)
root@blues-13288299:/#

The message ERROR 2002 (HY000): Can’t connect to MySQL server on helps me to find the following post and solve the issue.

Mastodon