Unknown MySQL server host 'mysql'

CMS Version

4.0.6.

Installation Method

Docker

Operating System

Debian GNU/Linux 11 (bullseye)

Issue

can’t connect to mysql

docker-compose logs cms-web

cms-web_1         | Configuring Database Settings
cms-web_1         | ERROR 2005 (HY000): Unknown MySQL server host 'mysql' (-2)
cms-web_1         | ERROR 2005 (HY000): Unknown MySQL server host 'mysql' (-2)
cms-web_1         | ERROR 2005 (HY000): Unknown MySQL server host 'mysql' (-2)
cms-web_1         | ERROR 2005 (HY000): Unknown MySQL server host 'mysql' (-2)
cms-web_1         | ERROR 2005 (HY000): Unknown MySQL server host 'mysql' (-2)
cms-web_1         | ERROR 2005 (HY000): Unknown MySQL server host 'mysql' (-2)
cms-web_1         | Setting up Maintenance
cms-web_1         | Protected Maintenance
cms-web_1         | ERROR 2005 (HY000): Unknown MySQL server host 'mysql' (-2)
cms-web_1         | ERROR 2005 (HY000): Unknown MySQL server host 'mysql' (-2)
cms-web_1         | Importing ca-certs
cms-web_1         | cp: cannot stat '/var/www/cms/ca-certs/*.pem': No such file or directory
cms-web_1         | cp: cannot stat '/var/www/cms/ca-certs/*.crt': No such file or directory
cms-web_1         | Updating certificates in /etc/ssl/certs...
cms-web_1         | 0 added, 0 removed; done.
cms-web_1         | Running hooks in /etc/ca-certificates/update.d...
cms-web_1         | done.
cms-web_1         | Setting up Quickchart
cms-web_1         | ERROR 2005 (HY000): Unknown MySQL server host 'mysql' (-2)
cms-web_1         | ERROR 2005 (HY000): Unknown MySQL server host 'mysql' (-2)
cms-web_1         | Configuring Maintenance
cms-web_1         | Removing web/install/index.php from production container
cms-web_1         | ERROR 2005 (HY000): Unknown MySQL server host 'mysql' (-2)
cms-web_1         | Configure PHP
cms-web_1         | Configure Apache
cms-web_1         | Starting cron
cms-web_1         | Starting webserver
cms-web_1         | AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 172.24.0.6. Set the 'ServerName' directive globally to suppress this message

calling over Browser:

Fatal Error - sorry this shouldn’t happen.
SQLSTATE[HY000] [2002] php_network_getaddresses: getaddrinfo for mysql failed: Name or service not known

I had a running 2.3.x Xibo version and tried to update up to 3.3. but also got this error. Then I tried to go back and used the backup files, I got the same error like above. Then I removed everything. clean up all Docker Images, container and everything in the folder. Now I tried directly the last version 4.0.6 and I got this error.

The only change I do is using an Apache2 to serve https like describe here Xibo for Docker | Xibo Digital Signage

What can I do to find the solution?

EDIT:
May I show also the logs from the db

cms-db_1          | 2024-01-25 12:29:19+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 8.0.36-1.el8 started.
cms-db_1          | 2024-01-25 12:29:21+00:00 [Note] [Entrypoint]: Switching to dedicated user 'mysql'
cms-db_1          | 2024-01-25 12:29:21+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 8.0.36-1.el8 started.
cms-db_1          | 2024-01-25 12:29:21+00:00 [Note] [Entrypoint]: Initializing database files
cms-db_1          | 2024-01-25T12:29:21.513291Z 0 [Warning] [MY-011068] [Server] The syntax '--skip-host-cache' is deprecated and will be removed in a future release. Please use SET GLOBAL host_cache_size=0 instead.
cms-db_1          | 2024-01-25T12:29:21.515662Z 0 [System] [MY-013169] [Server] /usr/sbin/mysqld (mysqld 8.0.36) initializing of server in progress as process 81
cms-db_1          | 2024-01-25T12:29:21.589681Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
cms-db_1          | 2024-01-25T12:29:25.482120Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
cms-db_1          | 2024-01-25T12:29:33.852258Z 6 [Warning] [MY-010453] [Server] root@localhost is created with an empty password ! Please consider switching off the --initialize-insecure option.
cms-db_1          | 2024-01-25 12:29:51+00:00 [Note] [Entrypoint]: Database files initialized
cms-db_1          | 2024-01-25 12:29:51+00:00 [Note] [Entrypoint]: Starting temporary server
cms-db_1          | 2024-01-25T12:29:52.209979Z 0 [Warning] [MY-011068] [Server] The syntax '--skip-host-cache' is deprecated and will be removed in a future release. Please use SET GLOBAL host_cache_size=0 instead.
cms-db_1          | 2024-01-25T12:29:52.211943Z 0 [System] [MY-010116] [Server] /usr/sbin/mysqld (mysqld 8.0.36) starting as process 123
cms-db_1          | 2024-01-25T12:29:52.253796Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
cms-db_1          | 2024-01-25T12:29:53.418597Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
cms-db_1          | 2024-01-25T12:29:53.942185Z 0 [Warning] [MY-010068] [Server] CA certificate ca.pem is self signed.
cms-db_1          | 2024-01-25T12:29:53.942239Z 0 [System] [MY-013602] [Server] Channel mysql_main configured to support TLS. Encrypted connections are now supported for this channel.
cms-db_1          | 2024-01-25T12:29:53.953167Z 0 [Warning] [MY-011810] [Server] Insecure configuration for --pid-file: Location '/var/run/mysqld' in the path is accessible to all OS users. Consider choosing a different directory.
cms-db_1          | 2024-01-25T12:29:53.985428Z 0 [System] [MY-011323] [Server] X Plugin ready for connections. Socket: /var/run/mysqld/mysqlx.sock
cms-db_1          | 2024-01-25T12:29:53.985487Z 0 [System] [MY-010931] [Server] /usr/sbin/mysqld: ready for connections. Version: '8.0.36'  socket: '/var/run/mysqld/mysqld.sock'  port: 0  MySQL Community Server - GPL.
cms-db_1          | 2024-01-25 12:29:54+00:00 [Note] [Entrypoint]: Temporary server started.
cms-db_1          | '/var/lib/mysql/mysql.sock' -> '/var/run/mysqld/mysqld.sock'
cms-db_1          | Warning: Unable to load '/usr/share/zoneinfo/iso3166.tab' as time zone. Skipping it.
cms-db_1          | Warning: Unable to load '/usr/share/zoneinfo/leap-seconds.list' as time zone. Skipping it.
cms-db_1          | Warning: Unable to load '/usr/share/zoneinfo/leapseconds' as time zone. Skipping it.
cms-db_1          | Warning: Unable to load '/usr/share/zoneinfo/tzdata.zi' as time zone. Skipping it.
cms-db_1          | Warning: Unable to load '/usr/share/zoneinfo/zone.tab' as time zone. Skipping it.
cms-db_1          | Warning: Unable to load '/usr/share/zoneinfo/zone1970.tab' as time zone. Skipping it.
cms-db_1          | 2024-01-25 12:29:57+00:00 [Note] [Entrypoint]: GENERATED ROOT PASSWORD: 7rj27FJvMgP684f8ynkaM8bxXYk+9jSb
cms-db_1          | 2024-01-25 12:29:57+00:00 [Note] [Entrypoint]: Creating database cms
cms-db_1          | 2024-01-25 12:29:58+00:00 [Note] [Entrypoint]: Creating user cms
cms-db_1          | 2024-01-25 12:29:58+00:00 [Note] [Entrypoint]: Giving user cms access to schema cms
cms-db_1          | 
cms-db_1          | 2024-01-25 12:29:58+00:00 [Note] [Entrypoint]: Stopping temporary server
cms-db_1          | 2024-01-25T12:29:58.254524Z 13 [System] [MY-013172] [Server] Received SHUTDOWN from user root. Shutting down mysqld (Version: 8.0.36).
cms-db_1          | 2024-01-25T12:30:05.816145Z 0 [System] [MY-010910] [Server] /usr/sbin/mysqld: Shutdown complete (mysqld 8.0.36)  MySQL Community Server - GPL.
cms-db_1          | 2024-01-25 12:30:06+00:00 [Note] [Entrypoint]: Temporary server stopped
cms-db_1          | 
cms-db_1          | 2024-01-25 12:30:06+00:00 [Note] [Entrypoint]: MySQL init process done. Ready for start up.
cms-db_1          | 
cms-db_1          | 2024-01-25T12:30:06.536961Z 0 [Warning] [MY-011068] [Server] The syntax '--skip-host-cache' is deprecated and will be removed in a future release. Please use SET GLOBAL host_cache_size=0 instead.
cms-db_1          | 2024-01-25T12:30:06.538784Z 0 [System] [MY-010116] [Server] /usr/sbin/mysqld (mysqld 8.0.36) starting as process 1
cms-db_1          | 2024-01-25T12:30:06.546990Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
cms-db_1          | 2024-01-25T12:30:07.130418Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
cms-db_1          | 2024-01-25T12:30:07.906440Z 0 [Warning] [MY-010068] [Server] CA certificate ca.pem is self signed.
cms-db_1          | 2024-01-25T12:30:07.906490Z 0 [System] [MY-013602] [Server] Channel mysql_main configured to support TLS. Encrypted connections are now supported for this channel.
cms-db_1          | 2024-01-25T12:30:07.941971Z 0 [Warning] [MY-011810] [Server] Insecure configuration for --pid-file: Location '/var/run/mysqld' in the path is accessible to all OS users. Consider choosing a different directory.
cms-db_1          | 2024-01-25T12:30:07.976332Z 0 [System] [MY-011323] [Server] X Plugin ready for connections. Bind-address: '::' port: 33060, socket: /var/run/mysqld/mysqlx.sock
cms-db_1          | 2024-01-25T12:30:07.976394Z 0 [System] [MY-010931] [Server] /usr/sbin/mysqld: ready for connections. Version: '8.0.36'  socket: '/var/run/mysqld/mysqld.sock'  port: 3306

Is there anybody who could help me to find the problem? May I miss some informations?

I always get this logs if I restart the Containers. The curios thing is, I got the same message with all versions I tried.

physik-info-02:/data/xibo # docker-compose logs 
Attaching to xibo_cms-web_1, xibo_cms-memcached_1, xibo_cms-xmr_1, xibo_cms-db_1, xibo_cms-quickchart_1
cms-db_1          | 2024-01-26 07:40:49+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 8.0.36-1.el8 started.
cms-db_1          | 2024-01-26 07:40:50+00:00 [Note] [Entrypoint]: Switching to dedicated user 'mysql'
cms-db_1          | 2024-01-26 07:40:50+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 8.0.36-1.el8 started.
cms-db_1          | '/var/lib/mysql/mysql.sock' -> '/var/run/mysqld/mysqld.sock'
cms-db_1          | 2024-01-26T07:40:51.190956Z 0 [Warning] [MY-011068] [Server] The syntax '--skip-host-cache' is deprecated and will be removed in a future release. Please use SET GLOBAL host_cache_size=0 instead.
cms-db_1          | 2024-01-26T07:40:51.192306Z 0 [System] [MY-010116] [Server] /usr/sbin/mysqld (mysqld 8.0.36) starting as process 1
cms-db_1          | 2024-01-26T07:40:51.212822Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
cms-db_1          | 2024-01-26T07:40:52.621335Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
cms-db_1          | 2024-01-26T07:40:53.745835Z 0 [Warning] [MY-010068] [Server] CA certificate ca.pem is self signed.
cms-db_1          | 2024-01-26T07:40:53.745883Z 0 [System] [MY-013602] [Server] Channel mysql_main configured to support TLS. Encrypted connections are now supported for this channel.
cms-db_1          | 2024-01-26T07:40:53.784300Z 0 [Warning] [MY-011810] [Server] Insecure configuration for --pid-file: Location '/var/run/mysqld' in the path is accessible to all OS users. Consider choosing a different directory.
cms-db_1          | 2024-01-26T07:40:53.960078Z 0 [System] [MY-011323] [Server] X Plugin ready for connections. Bind-address: '::' port: 33060, socket: /var/run/mysqld/mysqlx.sock
cms-db_1          | 2024-01-26T07:40:53.960214Z 0 [System] [MY-010931] [Server] /usr/sbin/mysqld: ready for connections. Version: '8.0.36'  socket: '/var/run/mysqld/mysqld.sock'  port: 3306  MySQL Community Server - GPL.
cms-web_1         | Waiting for MySQL to start - max 300 seconds
cms-web_1         | MySQL started
cms-web_1         | Configuring MySQL cnf file
cms-web_1         | Updating settings.php
cms-web_1         | ERROR 2005 (HY000): Unknown MySQL server host 'mysql' (-2)
cms-web_1         | New install
cms-web_1         | Provisioning Database
cms-web_1         | ERROR 2005 (HY000): Unknown MySQL server host 'mysql' (-2)
cms-web_1         | Phinx by CakePHP - https://phinx.org.
cms-web_1         | 
cms-web_1         | using config file /var/www/cms/phinx.php
cms-web_1         | using config parser php
cms-web_1         | using migration paths 
cms-web_1         |  - /var/www/cms/db/migrations
cms-web_1         | warning no environment specified, defaulting to: production
cms-web_1         | using adapter mysql
cms-web_1         | using database cms
cms-web_1         | ordering by creation time

Ok. I can’t solve the problem.

I am guessing somewhere at the server there is a network configuration which is not compatible with the xibo containers.

Fortunately I could reset the changes. Now I have to investigate what the problem could be, that the web container can’t connect the mysql container.

Ok, meanwhile I know much more of the problem.
It is the same issue described here:

But I ran Version 2.3.x and after I did this mysql update:

I got the same problem as before. The cms-web Container can’t connect the cms-db Container with the alias “mysql” but over the IP and even with “cms-db” the mysql connection from cms-web to cms-db work fine.

For me it looks like the docker-compose “links” flag don’t work. May this is the reason?
“The --link flag is a legacy feature of Docker. It may eventually be removed.”

But how can I solve this?

OK - I found the solution.

I edit the docker-compose.yml file and add a aliases flag for the cms-db service. Now the cms-db Container is linked in the cms-web Container again with “mysql” and everything is working as before.

And the reason it took so long for me to find the solution was: I didn’t understand how to access the default network, because the examples I found always mention a concrete docker network. So I missed the keyword “default” and my tries failed.

    cms-db:
        image: mysql:5.7
        volumes:
            - "./shared/db:/var/lib/mysql:Z"
        environment:
            - MYSQL_DATABASE=cms
            - MYSQL_USER=cms
            - MYSQL_RANDOM_ROOT_PASSWORD=yes
        mem_limit: 1g
        env_file: config.env
        restart: always
        networks:
           default:
             aliases:
                - mysql
3 Likes

Thank you very much, my English is bad, but your solution is beautiful

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.