0

I have a .NET application running on a windows 10 computer using docker and postgres. When I run using the

 "DockerTest": {
      "commandName": "Project",
      "launchBrowser": true,
      "launchUrl": "asset",
      "environmentVariables": {
        "ASPNETCORE_ENVIRONMENT": "Development"
      },
      "applicationUrl": "https://localhost:5001;http://localhost:5000"
    },

Connection string = "Server=localhost;Port=5433;Database=xxx;Uid=yyy;Pwd=zzz;",

option in VS2019 I can connect to my postgres database without problems.

When I try to run the application using the

 "Docker": {
      "commandName": "Docker",
      "launchBrowser": true,
      "launchUrl": "{Scheme}://{ServiceHost}:{ServicePort}/asset",
      "publishAllPorts": true,
      "useSSL": true
    },

option, I am getting errors connecting. Here is my connection string.

 "Database1": "Server=host.docker.internal;Port=5433;Database=xxx;Uid=yyy;Pwd=zzz;",

No matter what I try for a connection string I get CONNECTION WAS REFUSED or TIMEOUT errors.

Can anyone give me pointer as to what to try? I have gone over the message boards for two days and tries WINDOWS DEFENDER additions for com.docker.backend, I have tried different connection strings, I have tried many many other ways to solve this and have come up blank.

The end goal is to have docker run my REST API and have postgres installed on the same computer but not running in docker.

NEW EDIT: July 6 1:45 AM MST

inside the container I ran the following:

C:\app>ipconfig

Windows IP Configuration

Ethernet adapter Ethernet:

   Connection-specific DNS Suffix  . : allworx.activeis.ca
   Link-local IPv6 Address . . . . . : fe80::c06e:18b5:f9e0:48bb%4
   IPv4 Address. . . . . . . . . . . : 172.30.81.112
   Subnet Mask . . . . . . . . . . . : 255.255.240.0
   Default Gateway . . . . . . . . . : 172.30.80.1

C:\app>ping host.docker.internal

Pinging host.docker.internal [10.0.0.47] with 32 bytes of data:
Reply from 10.0.0.47: bytes=32 time<1ms TTL=127

NOTE : if I try to run my own app in the environment it actually works in with the 10.0.0.47 it works (even with host.docker.internal)... It is just from inside the container that it does not make the Postgres connection.

**PG_HBA.CONF FILE :** 
host    replication     all             127.0.0.1/32            md5
host    replication     all             ::1/128                 md5
host    all     all     172.17.0.1/16       md5

NEW EDIT: July 6 2:00 AM MST If I use the IP address of my other network IPs on my host they all work as long as I put them into the PG_HBA.CONF FILE (in the dockertest option)

Nothing seems to make the transition from container to host when I run with the DOCKER option. Even when I add the 10.0.0.47 to the file and run with HOST.DOCKER.INTERNAL (which translates to 10.0.0.47) it still does not work

**PG_HBA.CONF FILE :** 
host    replication     all             127.0.0.1/32            md5
host    replication     all             ::1/128                 md5
host    all     all     172.17.0.1/16       md5
host    all     all     10.0.0.47/16        md5
host    all     all     169.254.214.72/16   md5

C:\Users\Chris\source\repos\QuickTech.Com\QuickTechAPI>docker network ls
NETWORK ID          NAME                DRIVER              SCOPE
661118d67505        Default Switch      ics                 local
eae6a3536ef1        nat                 nat                 local
9d0b1f0209f6        none                null                local

I've seen a bridge or other network added in my hours of scouring the internet. Do I need to add a network to docker to make this transition?

NEW EDIT: July 6 11:00 AM MST

Host File in host computer
10.0.0.47 host.docker.internal
10.0.0.47 gateway.docker.internal
# To allow the same kube context to work on the host and the container:
127.0.0.1 kubernetes.docker.internal

I cannot open the hosts file (c:\windows\system32\drivers\etc) in the container to see what it contains.

Chris Dunlop
  • 135
  • 1
  • 13
  • How is your hosts file? Can you see host.docker.internal as an entry? – abestrad Jul 06 '20 at 05:47
  • Please see the edits I provided over the past 9 hours. – Chris Dunlop Jul 06 '20 at 17:20
  • Answer is here... https://stackoverflow.com/questions/62804279/windows-docker-container-networking-to-postges-on-host-windows-10/64177341#64177341 – Chris Dunlop Oct 02 '20 at 19:46
  • Answer is here: https://stackoverflow.com/questions/62804279/windows-docker-container-networking-to- postges-on-host-windows-10 – Chris Dunlop Oct 02 '20 at 19:47
  • Answer is here: https://stackoverflow.com/questions/62804279/windows-docker-container-networking-to-postges-on-host-windows-10 – Chris Dunlop Oct 02 '20 at 19:48
  • Answer is here: https://stackoverflow.com/questions/62804279/windows-docker-container-networking-to-postges-on-host-windows-10 – Chris Dunlop Oct 02 '20 at 19:50
  • Here is a link to where I finally solved this. https://stackoverflow.com/questions/62804279/windows-docker-container-networking-to-postges-on-host-windows-10 – Chris Dunlop Oct 02 '20 at 19:52

2 Answers2

1

docker run --name=XXX -d -p 8081:8081 --add-host=computername:IP address name This was what finally make it work

Chris Dunlop
  • 135
  • 1
  • 13
0

Have you tried with hos ip as your PostgreSQL host. I have just tested with asp.net core 3.1 and PostgreSQL both in windows 10 docker Linux separate container.

Its running without issue.

my connection string is

optionsBuilder.UseNpgsql("HOST=192.168.1.100;DataBase=TestIdentity;UserName=postgres;Password=*****;");

Yaseer Arafat
  • 81
  • 1
  • 4
  • 1
    Yes. I have. I have tried using every IP I could think of. Currently my host.docker.internal is 10.0.0.47 and I have tried creating a Postgres server with that IP, I have changed my conn string to that... I am positive this is a simple setting but I have tried everything I can think of. Being new to docker, I am frustrated. – Chris Dunlop Jul 15 '20 at 17:43
  • @Chris is there anyway I can lookup your issue. I think it's a simple config issue your are missing – Yaseer Arafat Aug 13 '20 at 09:09