phpmyadmin / docker

Docker container for phpMyAdmin
https://hub.docker.com/_/phpmyadmin
GNU General Public License v3.0
655 stars 451 forks source link

Connection refused from local forward database #429

Closed biladina closed 10 months ago

biladina commented 10 months ago

Problem:

I have database connection from jumphost that forward to my local machine with custom port, so in the end it is local db connection with custom port.. the problem is, I can't login to the database from phpmyadmin, it says connection refused, mysqli::real_connect(): (HY000/2002): Connection refused index I can login to mysql via console with command mysql -h 127.0.0.1 -P 8001 -u root -p, and also try login with app like DBeaver, it works, but can't login with phpmyadmin Screenshot_20230922_170702

Expected result:

can login and access the database

Environment:

host: 127.0.0.1 port: 8001 MySQL version: 8.0.34

docker-compose.yml

version: '3.2'

services:
  phpmyadmin:
    image: phpmyadmin:latest
    restart: always
    container_name: phpmyadmin
    env_file:
      - variables.env

networks:
  default:
    name: nginx-proxy
    external: true

variables.env

PMA_HOSTS: 172.18.0.1,127.0.0.1
PMA_PORTS: 3306,8001
PMA_ABSOLUTE_URI: http://pma.lan
PMA_PMADB: phpmyadmin
MAX_EXECUTION_TIME: 2000
UPLOAD_LIMIT: 300M
HIDE_PHP_VERSION: true
williamdes commented 10 months ago

Hi @biladina This is because it is impossible since the phpmyadmin container is not on your host but in it's own network. So 127.0.0.1 is it's own localhost.

The best to make it work would be to use network_mode: host and if the port 80 is already used, choose another one https://github.com/phpmyadmin/docker/blob/master/testing/docker-compose/docker-compose.testing-different-apache-port.yml#L29

biladina commented 10 months ago

okay, thank you very much.. I can't use network_mode: host because I use NGINX Proxy.. but I can solve my problem by change LocalForward from my jumphost configuration to use docker own IP address..

if anyone have same problem with jumphost connection..

then you can access your local forward database at IP 172.18.0.1 and port 8001

williamdes commented 10 months ago

Thank you for this interesting tip ! If I understand correctly you use ssh on the workstation to forward the MySQL connection into the container ?

One other way would be to forward the socket file with a Docker volume: https://github.com/phpmyadmin/docker/blob/272944cc5a10f7740acacbe2a35c2c1f6d9a98c7/testing/docker-compose/docker-compose.testing-one-socket-host.yml#L27

biladina commented 10 months ago

Thank you for this interesting tip ! If I understand correctly you use ssh on the workstation to forward the MySQL connection into the container ?

yes, exactly..

One other way would be to forward the socket file with a Docker volume:

https://github.com/phpmyadmin/docker/blob/272944cc5a10f7740acacbe2a35c2c1f6d9a98c7/testing/docker-compose/docker-compose.testing-one-socket-host.yml#L27

okay, I will try this one.. thank you..