1

I would like to connect my GUI database tool to my SQL Database via ssh and docker. Currently a can connect do database via terminal using ssh user@host and some docker-compose exec mydb ... command. But then, it's of course a command line access to db.

My needs / my question

Is there a way to have my GUI database tool to connect to that DB that way ? To be more explicit, i would like to connect to that db without any server change of any kind (really important point). So with only local configuration change. Maybe we can use the same way i can use by hand ?

What i tried

I already tried to use some ssh configuration in my config file like ProxyCommand in my ssh config file, but these command are executed in my computer...so i don't find any way to success with this.

I also searched many times anyone with the same will without success.

Somebody with great idea ?

TLeM4
  • 11
  • 1
  • Does the database container publish `ports:`? If it does, you can connect to it the same way you would a non-container database running on the host. (There's no particular reason to use `docker-compose exec` to interact with a database, other than to avoid installing the client application on the host.) – David Maze Jul 28 '20 at 10:33
  • Unfortunatly all the application is within docker containers and database container does not have any port open to outside of dockers... – TLeM4 Jul 28 '20 at 12:29

1 Answers1

0

There are some things to consider here.

  1. make sure the port mapping is valid in the docker-compose.yaml file, it should be something like
services:
  ...
  database:
    ...
    ports:
    - "3306:3306" # 3306 is the default Non-SSL port for MySQL database images
  1. make sure the machine you are running the database container on has no firewall rule to block incoming traffic
  2. make sure the in the database, the user you are trying to connect with has a whitelisted location. for example, if you want to be able to connect as root from anywhere, you need check the user table in the mysql database, and it should look something like:
mysql> select User, Host from user;
+------------------+-----------+
| User             | Host      |
+------------------+-----------+
| root             | %         |
| mysql.infoschema | localhost |
| mysql.session    | localhost |
| mysql.sys        | localhost |
| root             | localhost |
+------------------+-----------+
5 rows in set (0.00 sec)

mysql> 

In this case, the root user can connect to this particular DB from anywhere, because of the wildcard (%) host.

flamberge552
  • 83
  • 2
  • 8
  • Thanks to try to help me but this is server modification. I can't do that i'm sorry. As i said, i can't do any server change of any kind. Only local solution can be applied if any. – TLeM4 Jul 28 '20 at 12:18
  • If you are using docker-compose without any external port mapping then the services involved are only discoverable by eachother within the virtual network created by the compose file. – flamberge552 Jul 28 '20 at 14:37
  • I know. I asked this question to know if there are any way to connect a gui to the database using the same way that by hand. – TLeM4 Jul 28 '20 at 16:31