Thursday, February 8, 2018

SSH Connection from docker container to EXTERNAL server to read MySQL Database (query from docker) - development

SSH Connection from docker container to EXTERNAL server to read MySQL Database (query from docker)

I think there are alot of ‘kind of my solution’ questions and answer, but it is not THE answer to my solution. I’m pretty new to Docker, the new company I work at works with it. I know my way around PHP pretty well and making a SSH connection should not be too hard either.

But still: I just can’t figure it out.

I am using Laradock to run the docker containers.

So what I have done:

docker-compose up -d nginx php-fm mysql elasticsearch
ssh-keygen
ssh-copy-id name@server.com

Then I SSH directly from the workshop like this

docker-compose exec workspace bash
ssh -L *or* -R name@server.com

I can get the connection, AND I can do mysql on that server when logged in.

But: When I try to connect through my Laravel/PHP application:

$dbServerHost = 'ipofserver';
shell_exec("ssh -fNg -R 3316:$dbServerHost:3306 name@server");
$username = 'usernameofDB';
$password = 'PasswordOfDB';
$dbname = 'DatabaseName';
$connection = new mysqli($dbServerHost, $username, $password, $dbname, 3316);

It gives me: Connection refused, time and time again. I am pretty much lost here. I also used a laravel ssh tunnel but that was more confusing than it is now. As this tunnel used it’s own database env attributes to connect to an external database.

I am probably missing something really simple here.



from Laravel Questions and Answers https://laravelquestions.com/php/ssh-connection-from-docker-container-to-external-server-to-read-mysql-database-query-from-docker/
via Lzo Media

No comments:

Post a Comment