Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unable to connect outside database from Docker container App

we have two machine…one is windows machine and another in Linux machine. My application is running under Docker Container at Linux machine. our data base is running at Windows machine.our application need to get data from windows machine DB.

As we have given proper data source detail like IP, username ,password in our application. it works when we do not use docker container but when we use docker container it do not work.

Can anyone help me out to get this solution that how we can connect outside DB from Docker enabled application as we are totally new guys in term of Docker.

Any help would be much appreciated.

like image 440
Rama Shankar Avatar asked Jan 01 '18 17:01

Rama Shankar


1 Answers

Container's default network is "bridge",you should choose macvlan or host network.

method 1

docker run -d --net host image

this container will share your host IP address and will be able to access your database.

method 2

Use docker network create command to create a macvlan network,refrence here

then create your container by

docker run -d --net YOURNETWORK image

The container will have an IP address which is the same gateway with its host.

like image 83
亚里士朱德 Avatar answered Sep 24 '22 03:09

亚里士朱德