0

How can I connect local phpMyAdmin via SSH tunnel to a remote mySQL dockerized container (example.com)? This is the local phpMyadmin in docker compose:

pma:
  image: phpmyadmin/phpmyadmin
  container_name: pma
  environment:
    - PMA_ARBITRARY=1
    - 'PMA_ABSOLUTE_URI=https://pma.local/'
  volumes:
    - './config.user.inc.php:/etc/phpmyadmin/config.user.inc.php'
  restart: always

This is the custom configuration for PMA:

$cfg['Servers'][$i]['verbose']       = 'Localhost';
$cfg['Servers'][$i]['host']          = 'localhost';
$cfg['Servers'][$i]['port']          = '3306';
$cfg['Servers'][$i]['connect_type']  = 'tcp';
$cfg['Servers'][$i]['extension']     = 'mysqli';
$cfg['Servers'][$i]['compress']      = FALSE;
$cfg['Servers'][$i]['auth_type']     = 'cookie';
$i++;

$cfg['Servers'][$i]['verbose']       = 'Remote Server';
$cfg['Servers'][$i]['host']          = '127.0.0.1';
$cfg['Servers'][$i]['port']          = '3307';
$cfg['Servers'][$i]['connect_type']  = 'tcp';
$cfg['Servers'][$i]['extension']     = 'mysqli';
$cfg['Servers'][$i]['compress']      = FALSE;
$cfg['Servers'][$i]['auth_type']     = 'cookie';
$i++;

Using Core Tunnel I've set this in my local machine:

Port forwarding This is my test container on example.com:

docker run --name some-mysql -e MYSQL_ROOT_PASSWORD=my-secret-pw -d mysql:latest

Now, if I input on PMA the following (after enabling the tunnel):

Server: 127.0.0.1
User: root
Password: my-secret-pw

I get a:

mysqli_real_connect(): (HY000/2002): Connection refused

I'm really a newbie on this and surely doing something very bad. Could you please give me some advices? Many thanks in advance.

1 Answer 1

1

Docker create an internal network where he is possibly lying to Mysql, type "ifconfig" and "netstat -lptn" to view server data.

Try launching docker with "--network host" and assume the local ip, the mysql of the instance will listen on 127.0.0.1 or some other ip of your "physical" server.

Another option is to tell docker to do PAT and NAT with an option like this

-p 127.0.0.1:3107:3106

So you are telling him that all requests that arrive at the all interfaces 127.0.0.1 go to the docker instance: 3106

1
  • Thanks @asterissco I've used 127.0.0.1:3306:3306, now I can connect with raw mysql client but not with phpMyAdmin...do I need something else (e.g. other port)?
    – Jumpa
    Sep 26, 2019 at 16:05

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .