0

I want to perform the dump of a remote (not on local machine) mariadb database locally using a container created with the official mariadb image. The final goal is to import the remote database into the container to serve it on localhost.

Unfortunately I'm having trouble connecting to the external IP where the remote database is located from inside the Docker container. I can do that from outside the docker container.

I've created the container like this

docker run --name mariadb -p 3308:3306 -p 443:443 \
-e MYSQL_ROOT_PASSWORD=password1 \
-e MYSQL_DATABASE=test_database \
--add-host internal-host:remote_host_where_db_is_located \
-d mariadb:latest

Note that I added a redirect for port 443 and a host linked to the address where the database is located.

Then I tried to do

docker exec -i mariadb mariadb-dump --user=remote_user \
--host=internal-host \
--port=443 --password=remote_password --all-databases > dump.sql

This just hangs and nothing is produced, and I don't get any error...which is confusing.

Tried to just connect to the database from inside the container shell

mariadb --user=remote_user \
--host=internal-host --port=443 \
--password=remote_password remote_database_name

but this obviously also hangs.

Droid
  • 441
  • 1
  • 3
  • 18
  • Have you tried using the real remote host you passed to `--add-host`, i.e. `remote_host_where_db_is_located`? – markusjm Aug 10 '23 at 13:00
  • Yep, just out of curiosity. Also didn't work :( – Droid Aug 10 '23 at 13:47
  • A common sanity check is to run some command inside the container and make sure it's actually responding correctly. A convenient debug tool for this is `telnet` which should print some output that includes the server version if the server ends up responding and sending the handshake to the client. If you receive nothing, it's most likely not related to MariaDB but something in either the container system or the network. – markusjm Aug 10 '23 at 14:52
  • Well, thing is the official mariadb image does not have ping or telnet installed... So it's hard to make any troubleshooting. But what is confusing is that the connection with mariadb does not fail but just hangs – Droid Aug 14 '23 at 12:38
  • If you only need the tools for debugging a single problem, you can install them with `docker exec -ti name_of_my_container bash -c 'apt update && apt -y install iputils-ping telnet'`. – markusjm Aug 14 '23 at 20:31
  • Ok apparently I can ping the server and connects with telnet on port 443, so the forwarding is working. Unfortunately the connection inside the container still hangs... Is there a verbose option to be used with mariadb so that I can see where it stops working? I don't get any error message... The container logs do not contain any entry regarding this connection attempt. – Droid Aug 17 '23 at 12:48
  • Is MariaDB listening on port 443 on purpose? It uses the same port that HTTP traffic uses which makes me thing there could also be a hardware device or a firewall of some sorts that's causing these problems. If `telnet` connected but did not print a whole bunch of garbage, it means the server's handshake message wasn't received and the client is stuck waiting for that. This would suggest that there's something blocking the network between the container and MariaDB. – markusjm Aug 17 '23 at 15:46

0 Answers0