Phpmyadmin not connecting tot Mysql php_network_getaddresses: getaddrinfo for db failed

I have setup my first Docker containers to be able to have mysql8.o aside of the servers 5.7. version. I used Portainer to create a stack file. I’m on Debian12 server. Than tried to access phpmyadmin using the url . And it is throwing this error:

mysqli::real_connect(): php_network_getaddresses: getaddrinfo for db failed: Name or service not known
mysqli::real_connect(): (HY000/2002): php_network_getaddresses: getaddrinfo for db failed: Name or service not known

I’m not sure what is wrong in my yaml for the containers? Tried several solutions I came across online. Not succeeded getting it to work.
It’s also mentioning: Control host, username and password in config.inc.php

Good idea, but where to find that file? If I search for it through the CLi, I can only find the config.php for the non-container-one. So how to look into the Docker Container en locate that file there?

Looks like adding 127. helped to locate the db? But the last error still remains. mysqli::real_connect(): (HY000/2002): Connection refused

So is it only a matter of wrong credentials?

Further this is my stack right now. What Am I missing to get it working?

services:
  db:
	image: mysql:latest
	restart: always
	container_name: mysqlV8
	hostname: db
	environment:
	  MYSQL_ROOT_PASSWORD: my-root-pass-word-here
	  MYSQL_DATABASE: webserver1
	  MYSQL_USER: container_data1
	  MYSQL_PASSWORD: my-dbase-pass-word-here
	  MYSQL_TCP_PORT: 3310
	volumes:
	  - ./mysql_data:/var/lib/mysql
	ports:
	  - "3310:3310"

  phpmyadmin:
	image: phpmyadmin/phpmyadmin:latest
	restart: always
	container_name: phpmyadmin8
	depends_on:
	  - db
	environment:
	  PMA_HOST: 127.0.0.1:db
	  PMA_PORT: 3310
	  MYSQL_ROOT_PASSWORD: my-root-pass-word-here
	  PMA_USER: container_data1
	  PMA_PASSWORD: my-db-pass-word-here
	ports:
	  - "8080:80"

This should be:

	  PMA_HOST: db

Docker provides service discovery, based on the service, host, or container name for user defined networks. Docker compose deployments always create a user defined network, regardless whether it’s explicitly declared or not.

1 Like

If I leave that out the first two errors are returning… So I also tried to add PMA_SERVER: 127.0.0.1
stays the same still error.

Ok now I have worse problems. I noticed my regular mysql stopped working making all sites and mail unavailable.

systemctl start  mysql
Job for mysql.service failed because the control process exited with error code.
See "systemctl status mysql.service" and "journalctl -xeu mysql.service" for details.
systemctl status mysql.service:
mysql.service: Scheduled restart job, restart counter is at 5.
Dec 10 09:49:04 server1 systemd[1]: Stopped mysql.service - MySQL Community Server.
Dec 10 09:49:04 server1 systemd[1]: mysql.service: Start request repeated too quickly.
Dec 10 09:49:04 server1 systemd[1]: mysql.service: Failed with result 'exit-code'.
Dec 10 09:49:04 server1 systemd[1]: Failed to start mysql.service - MySQL Community Server.

So why is that happening? Firsttime I saw this I removed the Stack with mysql and phpmyadmin and after that is restarted. I even was able to run the stack again and at that time it still worked. Only after an hour it stopped working.

Could there be a problem mixing up of files or config files. The servers mysql and the container mysql have different ports. But I noticed that they might be using the same config files from volumes: /var/lib/mysql and /etc/mysql/my.cnf.
So default all php code need to use the 5.7mysql version and dbases which are already existing. And only for special cases I need to be able to use the container mysql with the newer version.
So I was expecting that the docker coantainer was completely stand alone. But apparently it is not? And using also the servers mysql dir - config?
How to avoid that so things will remain working normal?

I saw an set-up like this, but not sure if that is the way to have it?

services:
  mysql8:
    image: mysql:latest
    restart: always
    container_name: mysqlversion_8
    hostname: mysql8
    environment:
      MYSQL_ROOT_PASSWORD: 
      MYSQL_DATABASE: webserver1
      MYSQL_USER: container_data1
      MYSQL_PASSWORD: 
      MYSQL_TCP_PORT: 3310
      volumes:
        - mysql8:/var/lib/mysql
        - ./etc/mysql/my-8.cnf:/etc/mysql/my.cnf
      ports:
        - "3310:3310"
  phpmyadmin:
   image: phpmyadmin/phpmyadmin:latest
   restart: always
   container_name: phpmyadmin_for_8
   depends_on:
     - mysql8
   environment:
       PMA_HOST: mysql8
       PMA_PORT: 3310
       MYSQL_ROOT_PASSWORD: 
       PMA_USER: container_data
       PMA_PASSWORD: 
   ports:
        - "8080:80"

To resolve the above problems for now I replaced the server with a backup from the point things where still working. How to avoid getting this problem again?

Localhost of a container is private to the container, unless network_mode: host is used, which you are not using. Note: this is NOT a recommendation to use the network_mode: host.

localhost (=127.0.0.1) is not shared between host and container, or between multiple container. Everyone of them has their own localhost.

If your native mysql server does not bind the host port, you used to publish the mysql container port, and did not use the same folder to store the data, your current issue with the non-containerized version shouldn’t be related to the containerized version

Unless the files are located in ./mysql_data relative to the path where you compose file is stored: impossible.

A container has its own filesytem, it can only see/access from the host filesystem what your map into a container path as volume.

It is. I am afraid, that the most reasonable explanation is that your lack of understanding just makes you draw wrong conclusions.

From what you shared with us, there is no evidence that the containers are responsible for what you experience. Either there are other configurations at play that you didn’t share with us, or it appears to be pure coincidental.

Your containerized phpmyadmin should be able to talk to the containerized database in the same compose file. The database only binds port 3310 on the host (left side of the port mapping) and has access to the ./mysql_data folder. You phpmyadmin container only binds host port 3310. Appart from that, it is not able to bind other host ports, or access anything from the host filesystem.

Unless ./mysql_data happens to be a folder that is used by the native mysql instance, there is now way the compose file you shared is responsible for what you experienced.

Ok thanks for your feedback. Where is that ./msql_data folder located?
I only can find /var/lib/mysql where I see all my regular mysql dbase data.

Will the above pasted config work? I will try again.

I thought this would be coved by this:

My first thought was to write that you should know because you use docker compose…
then I remember that you use Portainer.

So the compose file is deployed from the perspective of the Portainer process inside a Portainer container. Worst case this means that ./mysql_data folder is “somewhere” in the Portainer container’s file system. The same “somewhere” where Portainer stores it’s compose files. Portainer itself already is not able to see anything from your host filesystem, other than what you used as volume, so you can’t use absolute paths, unless you bind a host path into the Portainer container using the same container path.

Please share following things:

  • the exact command or compose file content you used to create the Portainer container.
  • A host path that you want to use as a base path for all compose projects, where you want persistent data to be stored.

This allows me to update your shared configs, so that you can work with absolute paths, that result that data is actually written on the host.

Getting a bit further but still not working.

The mysql8 container is the problem one.

This is what I see in the log after restarting the container:

2025-12-11T14:28:06.352844Z 0 [System] [MY-013169] [Server] /usr/sbin/mysqld (mysqld 8.0.44) initializing of server in progress as process 79
2025-12-11T14:28:06.352895Z 0 [ERROR] [MY-010338] [Server] Can't find error-message file '/usr/share/mysql/errmsg.sys'. Check error-message file location and 'lc-messages-dir' configuration directive.
2025-12-11T14:28:06.354188Z 0 [ERROR] [MY-010457] [Server] --initialize specified but the data directory has files in it. Aborting.
2025-12-11T14:28:06.354261Z 0 [ERROR] [MY-010187] [Server] Could not open file '/var/log/mysql/error-8.log' for error logging: No such file or directory
2025-12-11T14:28:06.354319Z 0 [ERROR] [MY-013236] [Server] The designated data directory /var/lib/mysql/ is unusable. You can remove all files that the server added to it.
2025-12-11T14:28:06.354326Z 0 [ERROR] [MY-010119] [Server] Aborting
2025-12-11T14:28:06.354511Z 0 [System] [MY-010910] [Server] /usr/sbin/mysqld: Shutdown complete (mysqld 8.0.44)  MySQL Community Server - GPL.
2025-12-11 14:28:10+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 8.0.44-1debian12 started.
2025-12-11 14:28:10+00:00 [Note] [Entrypoint]: Switching to dedicated user 'mysql'
2025-12-11 14:28:10+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 8.0.44-1debian12 started.
2025-12-11 14:28:11+00:00 [Note] [Entrypoint]: Initializing database files
2025-12-11T14:28:11.078502Z 0 [Warning] [MY-011070] [Server] 'Disabling symbolic links using --skip-symbolic-links (or equivalent) is the default. Consider not using this option as it' is deprecated and will be removed in a future release.
2025-12-11T14:28:11.078609Z 0 [System] [MY-013169] [Server] /usr/sbin/mysqld (mysqld 8.0.44) initializing of server in progress as process 79
2025-12-11T14:28:11.078647Z 0 [ERROR] [MY-010338] [Server] Can't find error-message file '/usr/share/mysql/errmsg.sys'. Check error-message file location and 'lc-messages-dir' configuration directive.
2025-12-11T14:28:11.085125Z 0 [ERROR] [MY-010457] [Server] --initialize specified but the data directory has files in it. Aborting.
2025-12-11T14:28:11.085221Z 0 [ERROR] [MY-010187] [Server] Could not open file '/var/log/mysql/error-8.log' for error logging: No such file or directory
2025-12-11T14:28:11.085300Z 0 [ERROR] [MY-013236] [Server] The designated data directory /var/lib/mysql/ is unusable. You can remove all files that the server added to it.
2025-12-11T14:28:11.085308Z 0 [ERROR] [MY-010119] [Server] Aborting
2025-12-11T14:28:11.085560Z 0 [System] [MY-010910] [Server] /usr/sbin/mysqld: Shutdown complete (mysqld 8.0.44)  MySQL Community Server - GPL.
2025-12-11 14:28:18+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 8.0.44-1debian12 started.
2025-12-11 14:28:18+00:00 [Note] [Entrypoint]: Switching to dedicated user 'mysql'
2025-12-11 14:28:18+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 8.0.44-1debian12 started.
2025-12-11 14:28:19+00:00 [Note] [Entrypoint]: Initializing database files
2025-12-11T14:28:19.240831Z 0 [Warning] [MY-011070] [Server] 'Disabling symbolic links using --skip-symbolic-links (or equivalent) is the default. Consider not using this option as it' is deprecated and will be removed in a future release.
2025-12-11T14:28:19.240996Z 0 [System] [MY-013169] [Server] /usr/sbin/mysqld (mysqld 8.0.44) initializing of server in progress as process 79
2025-12-11T14:28:19.241037Z 0 [ERROR] [MY-010338] [Server] Can't find error-message file '/usr/share/mysql/errmsg.sys'. Check error-message file location and 'lc-messages-dir' configuration directive.
2025-12-11T14:28:19.242422Z 0 [ERROR] [MY-010457] [Server] --initialize specified but the data directory has files in it. Aborting.
2025-12-11T14:28:19.242491Z 0 [ERROR] [MY-010187] [Server] Could not open file '/var/log/mysql/error-8.log' for error logging: No such file or directory
2025-12-11T14:28:19.242563Z 0 [ERROR] [MY-013236] [Server] The designated data directory /var/lib/mysql/ is unusable. You can remove all files that the server added to it.
2025-12-11T14:28:19.242569Z 0 [ERROR] [MY-010119] [Server] Aborting
2025-12-11T14:28:19.246949Z 0 [System] [MY-010910] [Server] /usr/sbin/mysqld: Shutdown complete (mysqld 8.0.44)  MySQL Community Server - GPL.

After this I made sure the “missing” files are created in the mentioned dirs. Might be a matter of owner or rights why it can not find it or open it? Is says remove data from /var/lib/mysql/
but that is my servers mysql data storage so can not delete that.

this is my (stack) yaml:** which I used though portainer.

services:
db:
image: mysql:8.0.44-bookworm
restart: always
container_name: mysqlV8
hostname: db
environment:
MYSQL_ROOT_PASSWORD:
MYSQL_DATABASE: webserver1
MYSQL_USER: admin_db_user
MYSQL_PASSWORD:
MYSQL_TCP_PORT: 3307
volumes:
- ./mysql_data:/var/lib/mysql
- /etc/mysql/my-8.cnf:/etc/mysql/my.cnf
ports:
- “3307:3307”

phpmyadmin:
image: phpmyadmin/phpmyadmin:latest
restart: always
container_name: phpmyadmin8
depends_on:
- db
environment:
PMA_HOST: db
PMA_PORT: 3307
MYSQL_ROOT_PASSWORD:
PMA_USER: admin_db_user
PMA_PASSWORD:
ports:
- “8080:80”

this is in the my-8.cnf file maybe need some adjustment?

t[client]
port            = 3307
socket          = /var/run/mysqld/mysqld.sock

[mysqld_safe]
pid-file        = /var/run/mysqld/mysqld.pid
socket          = /var/run/mysqld/mysqld.sock
nice            = 0

[mysqld]
user            = mysql
pid-file        = /var/run/mysqld/mysqld.pid
socket          = /var/run/mysqld/mysqld.sock
port            = 3307
basedir         = /usr
datadir         = /var/lib/mysql
tmpdir          = /tmp
lc-messages-dir = /usr/share/mysql
explicit_defaults_for_timestamp
show_compatibility_56 = ON

Instead of skip-networking the default is now to listen only on

localhost which is more compatible and is not less secure.

bind-address    = 127.0.0.1

log-error       = /var/log/mysql/error-8.log

Recommended in standard MySQL setup

#sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES

Disabling symbolic-links is recommended to prevent assorted security risks

symbolic-links=0

IMPORTANT: Additional settings that can override those from this file!

The files must end with ‘.cnf’, otherwise they’ll be ignored.



!includedir /etc/mysql/conf.d/

innodb_buffer_pool_size=100M
max_allowed_packet=1024M
net_read_timeout=31536000
net_write_timeout=31536000




It doesn’t help me to help you to troubleshoot the issue if you,

  • ignore what I write: if you don’t understand something, please write how you understood it, so we can clarify it
  • don’t respond to my last post at all, and especially don’t share what I asked for.

Not intended to not answer you. But was already trying to sort out some more info and tried some things.

  • the exact command or compose file content you used to create the Portainer container.
    so you meant Portainer itself? Or the Mysql container created in Portainer?

  • A host path that you want to use as a base path for all compose projects, where you want persistent data to be stored.

    • the host path could be /var/docker/mysq

For the installation I followed this how to: How to Install Portainer Docker UI on Debian: Step-by-Step Guide

I updated Portainer to the latest version as explained on their Portainer website.

docker volume ls
DRIVER VOLUME NAME
local 0bff932a99cd1412accb87395f1fb3ac37c208eeb3d2f3c55afbb0945695ae9d
local portainer_data

some more info I found:

:~# docker volume inspect portainer_data
[
{
“CreatedAt”: “2025-12-09T14:40:26+01:00”,
“Driver”: “local”,
“Labels”: null,
“Mountpoint”: “/var/lib/docker/volumes/portainer_data/_data”,
“Name”: “portainer_data”,
“Options”: null,
“Scope”: “local”
}
]

Made it a step further. Seems that the container and mysql are running now. I adapted the my-8.cnf file. Left some parts out of it which seems to interfere. Still cannot log in into it with phpmyadmin dough.

2025-12-11T16:26:01.422772Z 0 [System] [MY-011323] [Server] X Plugin ready for connections. Bind-address: ‘::’ port: 33060, socket: /var/run/mysqld/mysqlx.sock
2025-12-11T16:26:01.422869Z 0 [System] [MY-010931] [Server] /usr/sbin/mysqld: ready for connections. Version: ‘8.0.44’ socket: ‘/var/run/mysqld/mysqld.sock’ port: 3307 MySQL Community Server - GPL.

mysqli::real_connect(): (HY000/2002): Connection refused

Absolutely. That’s why I asked about it.

The problem with Portainer is, that it expects the user to understand how containers work. I skimmed through the documentation earlier today, and couldn’t find a description that guides beginners about why they experience this problem, or describe how to fix it.

This is the command I found in the docs:

docker run -d -p 8000:8000 -p 9000:9000 --name=portainer --restart=always -v /var/run/docker.sock:/var/run/docker.sock -v portainer_data:/data portainer/portainer

With this your volumes are indeed either written into the container filesystem, or into the portainer_data volume. Like i wrote earlier: a container will not be able to see anything from the host filesytem, unless it’s mounted into the container.

The reason I asked for this is, because you will need to map the host folder into the same path on the Portainer container. This is required so Portainer can verify the existing of the path when it deploys a stack, before creating the container. Once the container is created, it will run on the Docker Engine (as a sibling to the Portainer container), which will then bind the host path into the container path.

I asked for a base folder, so you don’t have to map multiple specific host paths into their matching Portainer folder, in order that it’s able to verify their existance. I will remove the subfolder mysq in the following docker run command to re-create Portainer (make sure to delete the container before):

docker run -d -p 8000:8000 -p 9000:9000 --name=portainer --restart=always \
-v /var/run/docker.sock:/var/run/docker.sock \
-v portainer_data:/data portainer/portainer \
-v /var/docker:/var/docker \
portainer/portainer

Note: make sure /var/docker exists on the host!

Once the Portainer container is recreated, you need to modify your database service’s volume in your stack like this:

services:
  db:
    ...
	volumes:
	  - /var/docker/mysql:/var/lib/mysql:

This way Portainer is able to verify that /var/docker/mysql exists, and the docker engine is able to bind the host path /var/docker/mysql into the container path /var/lib/mysql.

Note: if you hadn’t used Portainer, you wouldn’t have the problems with the bind volumes that you experienced.

Update: please start with a minimal configuration of your stack, then add configuration properties as needed. Make sure you understand every property you have in your stack compose configuration!

Thanks for the extended reply and your help.

Is it ok if I remove that from within the portainer gui? Or do I need to remove it from within the terminal?

I think this is what I need to run. Or do I also have to remove the other 2 containers (mysql and phpmyadmin)?:slight_smile:

docker rm portainer

or

docker rm --volumes portainer

Or is it not needed to remove the volumes. Is there any risk the folder /var/lib/mysql will be removed?
After the recent update to version 2.33.5 portainer is now on port 9443.

I used this to upgrade:

docker run -d -p 8000:8000 -p 9443:9443 --name=portainer --restart=always -v /var/run/docker.sock:/var/run/docker.sock -v portainer_data:/data portainer/portainer-ce:lts

If I just add your additional code lines to it

-v /var/docker:/var/docker \ portainer/portainer

is that ok ?

I run below commands and ending up with an error:

 docker stop portainer

 docker rm portainer

docker run -d -p 8000:8000 -p 9443:9443 --name=portainer --restart=always -v /var/run/docker.sock:/var/run/docker.sock -v portainer_data:/data portainer/portainer-ce:lts -v /var/docker:/var/docker portainer/portainer

~# docker ps -a
CONTAINER ID   IMAGE                          COMMAND                  CREATED              STATUS                          PORTS                                                              NAMES
896a8e9d2062   portainer/portainer-ce:lts     “/portainer -v /var/…”   About a minute ago   Restarting (1) 10 seconds ago                                                                      portainer
3a673f399355   phpmyadmin/phpmyadmin:latest   “/docker-entrypoint.…”   15 hours ago         Up 15 hours                     0.0.0.0:8080->80/tcp, [::]:8080->80/tcp                            phpmyadmin8
6715e7f7f345   mysql:8.0.44-bookworm          “docker-entrypoint.s…”   15 hours ago         Up 15 hours                     3306/tcp, 33060/tcp, 0.0.0.0:3307->3307/tcp, [::]:3307->3307/tcp   mysqlV8

~# docker logs portainer
portainer: error: unknown short flag ‘-v’, try --help
portainer: error: unknown short flag ‘-v’, try --help

I am not using Portainer (I am not a fan of clickOps and found Portainer too cumbersome to use), so I don’t know the answer. Though wouldn’t it make more sense to delete it from the terminal?

You need to stop and remove the comtainer:

docker stop portainer
docker rm portainer

Depending on whether you want to start with a fresh slate (and configure Portainer from scratch), you would need to remove the volume as well. Since there might be data in the volume that is not supposed to be in there, I would recommend deleting it:

docker volume rm portainer_data

Can you share your thoughts why you think this could happen? Host folders are never deleted by deleting a container.

It requires a -v before the bind volume mapping, and the \ is a line continuation character at the end of the line. It will result in an error, if it’s somewhere else.

It should look like this:

docker run -d -p 8000:8000 -p 9443:9443 --name=portainer --restart=always -v /var/run/docker.sock:/var/run/docker.sock -v portainer_data:/data -v /var/docker:/var/docker \ portainer/portainer-ce:lts

Ok I have it working again with your suggestions. Also adapted the Stack. But still can’t log in. All attempts ending up with the error:

mysqli::real_connect(): (HY000/2002): Connection refused

So I went looking into the info and I am wondering if the missing the Host-ip part for the 3307 port the problem?

(most important parts of the: docker inspect mysqlV8 output

,
            "NetworkMode": "mysql_version_8_default",
            "PortBindings": {
                "3307/tcp": [
                    {
                        "HostIp": "",      (WHY IS THIS EMPTY?? )
                        "HostPort": "3307"
                    }


,
        "Mounts": [
            {
                "Type": "bind",
                "Source": "/var/docker/mysql",
                "Destination": "/var/lib/mysql",
                "Mode": "rw",
                "RW": true,
                "Propagation": "rprivate"
            },
            {
                "Type": "bind",
                "Source": "/etc/mysql/my-8.cnf",
                "Destination": "/etc/mysql/my.cnf",
                "Mode": "rw",
                "RW": true,
                "Propagation": "rprivate"
            }
        ],

The output of the port-check.

:~# lsof -i :3307
COMMAND      PID USER   FD   TYPE  DEVICE SIZE/OFF NODE NAME
docker-pr 249389 root    7u  IPv4 1614600      0t0  TCP *:3307 (LISTEN)
docker-pr 249395 root    7u  IPv6 1614601      0t0  TCP *:3307 (LISTEN)
~# lsof -i :3306
COMMAND    PID    USER   FD   TYPE  DEVICE SIZE/OFF NODE NAME
mysqld   79777   mysql   15u  IPv4  643114      0t0  TCP localhost:mysql (LISTEN)
mysqld   79777   mysql   23u  IPv4 1630171      0t0  TCP localhost:mysql->localhost:54072 (ESTABLISHED)
auth    250735 dovecot   20u  IPv4 1630462      0t0  TCP localhost:54072->localhost:mysql (ESTABLISHED)

Wow I’m finally in. Found the problem. Was created by myself in the stack config.

services:
  db:
    image: mysql:8.0.44-bookworm
    restart: always
    container_name: mysqlV8
    hostname: db
    environment:
      MYSQL_ROOT_PASSWORD: 
      MYSQL_DATABASE: webserver1db
      MYSQL_USER: admin_webserver1db
      MYSQL_PASSWORD: 
      MYSQL_TCP_PORT: 3307
    volumes:
      - /var/docker/mysql:/var/lib/mysql
      #- /etc/mysql/my-8.cnf:/etc/mysql/my.cnf
    ports:
      - "3307:3306"

  phpmyadmin:
    image: phpmyadmin/phpmyadmin:latest
    restart: always
    container_name: phpmyadmin8
    depends_on:
      - db
    environment:
      PMA_HOST: db
      PMA_PORT: 3307

    ports:
      - "8080:80"

The greyed code line out was apparently causing problems. I thought this was needed to tell mysql to use port 3307 but apparantly it is not working that way.
So if needed? Were to adapt the my.cnf file for this mysql-container?

So Although this works. And I can log into phpmyadmin and the mysql dabase, I get some new problems accessing the database from domain which need the mysql8 database to run. Just not getting access:

Do I also need some additional things into the Apache2 Vhost config to be able to use mysql8- in the docker container? I was just thinking if I can log in from the browsers-url it also should be possible from inside a websites php? It s hosted on the same server. using port 3306 I get all the servers mysql dbases (which i do not need now. So it must connect to 3307 instead.

There is also an option to connect to the database through a socked:

Connecting to the database with given settings failed: An exception occurred in the driver: Access denied for user 'admin_webserver1db'@'localhost' (using password: YES)

Any idea how to get that working? Thanks.