问题
I am a newbie to docker. I am running Postgresql running on my local machine (i.e. On Mac OS). My application is running in docker. What I want is my application should be able to access PostgreSQL(has got a lot of production data, which can`t be run on docker) service from docker. How to do it? Could anyone give me an example of doing so?
Many thanks in advance
回答1:
Finally, I found a solution to link external services inside docker. Added below lines in the docker-compose.yaml:
extra_hosts:
my-local-host: 10.0.0.10 #Local machine IP
environment:
- SERVER=http://my-local-host:3000
回答2:
At my case (I have docker running on Ubuntu) there is a docker0 network interface and the host takes the IP 172.17.0.1. Every container that will attach to the default network will get an IP within the 172.17.0.X range. This way, containers can access services running on the host by talking to 172.17.0.1[:port] because they're on the same network...
But, things are different for Docker for Mac...
From: Networking features in Docker for Mac
Known limitations, use cases, and workarounds
Following is a summary of current limitations on the Docker for Mac networking stack, along with some ideas for workarounds. There is no
docker0bridge on macOSBecause of the way networking is implemented in Docker for Mac, you cannot see a
docker0interface in macOS. This interface is actually withinHyperKit.Use cases and workarounds
I want to connect from a container to a service on the host
The Mac has a changing IP address (or none if you have no network access). From
17.12onwards our recommendation is to connect to the special Mac-only DNS namedocker.for.mac.host.internal, which resolves to the internal IP address used by the host.
来源:https://stackoverflow.com/questions/49148920/how-to-connect-external-service-from-docker-service