Unable to access Postgres SQL on host machine inside docker
I have a unique problem. I’m create an ASP.NET core application that will be accessing a postgres SQL on a host machine or host network. For development purpose I have community edition of docker on Windows 10 machine. I also have the POSTGRESQL on the same windows machine. I have exposed the ASP.NET service on the port 5000. The docker is a Linux docker and not windows docker I have build the docker using the below dockerfile
FROM microsoft/aspnetcore:2.0
ENV ASPNETCORE_URLS="http://*:5000"
COPY . /app
WORKDIR /app
EXPOSE 5000
ENTRYPOINT [“dotnet”, “ContainerDASample.dll”]
when I run the docker normally using the command
docker run -p 5000:5000 --name containerda containerda-img**
The health check (which is nothing but a Http 200 with a message )is working good but the endpoints that access the postgres are failing*
When I run the docker command using the below command
docker run -p 5000:5000 --network=“host” --name containerda containerda-img**
The health check itself fails.*
So totally I’m at loss to understand how to make this application work with container
Adding more information as per comments
-
Yes when I set the --network=host the endpoint localhost:5000
-
I use docker on windows 10 with Hyper-V
The health check simply not reachable. I ran the docker command as below docker run -p 5000:5000 --network=host --name containerda containda-img
You can use this hostname docker.for.win.localhost. https://docs.docker.com/docker-for-windows/release-notes/#docker-community-edition-17060-win13-release-notes-2017-06-01-17060-rc1-ce-win13-edge
Sorry the issue got accidentally closed. The above command did not work. The command I ran was docker run -p 5000:80 --network="docker.for.win.localhost" --name containerda containerda-img
The output I got was Error response from daemon: network docker.for.win.localhost not found
The version of docker I use is Docker version 17.06.2-ce, build cec0b72
If postgres is running on the windows host, you can access it on docker.for.win.localhost:5432 - you don't need to do any networking stuff
@friism Thanks that did the trick. Now I'm able to access the postgres on host machine. The Changes I made to the connection setting is as "credentials": "Server=docker.for.win.localhost;Port=5432;Database=ASPNETCORE;User Id=postgres;Password=venkat78" and it did the work
I need another help. Is there way by which we can access an a database in Azure from my container if so how should I do that
Thank you @friism this method worked for me!
Thanks @VenkateshSrini @friism its worked for me
Closed issues are locked after 30 days of inactivity. This helps our team focus on active issues.
If you have found a problem that seems similar to this, please open a new issue.
Send feedback to Docker Community Slack channels #docker-for-mac or #docker-for-windows. /lifecycle locked