Answer the question
In order to leave comments, you need to log in
How to forward a port from a host inside a docker container?
You need to connect from inside the docker container to the MySQL database on another server. At the same time, an ssh tunnel is forwarded on the host and the database is available on port 3307.
Inside the MySQL container, the server containing the database with Federated tables referring to the remote server, but does not work, because the container has its own 127.0.0.1 and the port is not forwarded to it. There is no SSH in the container, so just taking it and forwarding it will not work. You need to somehow forward 127.0.0.1:3307 from the host to the container. And also on 127.0.0.1, because on a remote server bind-address=127.0.0.1 and cannot be changed.
What can you suggest? The whole Internet got out.
I will describe in more detail:
There are 2 servers. For example, 1.1.1.1 and 2.2.2.2
on 1.1.1.1 production server, it has 2 databases, conditionally fastdata and userdata.
In the first, the data required by all users is updated almost every second. In the second, user data is also frequently updated, but not so.
On 2.2.2.2 test server. There's a whole lot there. Incl. as many as 2 MySQL servers. One on the host, the other in the container. Total:
1) Server on the host, on the standard port 3306
2) Also port forwarded from 1.1.1.1 - bound to 3307
3) Base in the container (MariaDB 10.1
. the server should be a copy of the production database, but with other users (test). Those. the userdata base is there, but fastdata should be. absolutely identical to the base from the sale at any time. Assumed solution via Federated tables, i.e. looks like that:
ENGINE=FEDERATED DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci CONNECTION='mysql://root:[email protected]:3307/fastdata/table1';
Answer the question
In order to leave comments, you need to log in
In general, the solution turned out to be simple:
Those. as I expected via --net=host - this way the container works on the host network and there is no need to redirect anything. /etc/mysql is really not forwarded to change my.cnf, but /etc/mysql/conf.d is calmly forwarded, and the mariadb.cnf file is in it, in which the port change to 3308 is registered.
The problem is solved.
But what if you specify the ip address of the network card to which the ssh tunnel is forwarded?
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question