简体   繁体   中英

How to connect to a docker container database on a remote ubuntu server?

I've tried searching left and right and I can't find a solution to my problem. I can connect perfectly fine on my localhost to my docker container's database (simply by connecting to localhost/127.0.0.1/ubuntuip) on dbeaver, but when it comes to connecting to my docker mysql container on the remote ubuntu server (so not the ubuntu running on my computer), it doesn't work.

Things I've tried

  • Connecting to the ubuntu server ip (by doing "hostname -I";
  • Connecting to the ip shown when I run "curl http://checkip.amazonaws.com" on the remote ubuntu server (I ssh into it);
  • Connecting to the docker container ip when I do inspect -f '{{range.NetworkSettings.Networks}}{{.IPAddress}}{{end}}' container_name_or_id on the remote ubuntu server.

None of those worked and I'm getting a bit lost honestly. When I do select host, user from mysql.user on the remote ubuntu server, I get this:

mysql> select host, user from mysql.user;

+-----------+------------------+
| host      | user             |
+-----------+------------------+
| %         | root             |
| localhost | mysql.infoschema |
| localhost | mysql.session    |
| localhost | mysql.sys        |
| localhost | root             |
+-----------+------------------+

From what I understand, I should be able to connect to it since I allow any host (this is dev, not prod). I can easily ping my db container, the tables are created fine in it and everything. I just can't connect to it from my Dbeaver.

Any help is appreciated, thanks:)

Fixed it. Just like David Maze said, I had to connect to the same url as the one I used to ssh, but I had already tried that. What I had to do was to also go in the SSH tab on dbeaver and add the host (same url) and select the auth method to "public key" and I selected my ssh key folder (id_rsa) which is located at \\wsl$\Ubuntu-18.04\home\user\.ssh\id_rsa . I left the "passphrase" blank and now it works!

Thanks for the help!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM