5

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.

3
  • what database are you using? Do you have some logs? maybe something about the database permissions on specific IPs? Commented Jan 1, 2018 at 18:04
  • Please provide the environment details Commented Jan 1, 2018 at 20:52
  • Please provide the correct error or effect of what you are experiencing. "It doesn't work" is not specific enough. Commented Jan 1, 2018 at 22:22

2 Answers 2

8

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.

Sign up to request clarification or add additional context in comments.

Comments

0

There are a lot of issues that could be affecting your container's ability to communicate with your database. In the future you should compose your question with as much detail as possible. To correctly answer this you will, at a minimum, need to include the following details:

  • Linux distribution name & version
  • Docker version
  • Output of docker inspect from the container
  • Linux firewall configuration
  • Network configuration

Is your Windows machine running on the same local network / subnet as your Linux machine? If so, please provide information about the subnet, as the default bridge set up by Docker may restrict access to local resources, whereas those over a wide area network would still be accessible.

You can try passing the --network=host option to your docker run command like so: docker run --network=host <image name>. Doing so eliminates the need to specify port mappings in your run command, as they are ignored when using the host's network.

Please edit your question and include the above requested details to get a complete answer.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.