0

OK.. Sorry to clog up this site with endless questions. I have a .NET REST API that works in DOCKER. (Windows container) But, the moment I try to connect to Postgres on my host I am unable to connect. I get unable to connect, request timed out, connection was actively refused... I have modified my connection string over a thousand times trying to get this to work.

when I look at docker networks is get:

C:\Windows\SysWOW64>docker network ls
NETWORK ID          NAME                DRIVER              SCOPE
4c79ae3895aa        Default Switch      ics                 local
40dd0975349e        nat                 nat                 local
90a25f9de905        none                null                local

when I inspect my container, it says it is using NAT for network.

C:\Windows\SysWOW64>docker network inspect nat
[
    {
        "Name": "nat",
        "Id": "40dd0975349e1f4b334e5f7b93a3e8fb6aef864315ca884d8587c6fa7697dec5",
        "Created": "2020-07-08T15:02:17.5277779-06:00",
        "Scope": "local",
        "Driver": "nat",
        "EnableIPv6": false,
        "IPAM": {
            "Driver": "windows",
            "Options": null,
            "Config": [
                {
                    "Subnet": "172.22.96.0/20",
                    "Gateway": "172.22.96.1"
                }
            ]
        },
        "Internal": false,
        "Attachable": false,
        "Ingress": false,
        "ConfigFrom": {
            "Network": ""
        },
        "ConfigOnly": false,
        "Containers": {
            "0d2dc2658a9948d84b01eaa9f5eb5a0e7815933f5af17e5abea17b82a796e1ec": {
                "Name": "***MyAPI***",
                "EndpointID": "3510dac9e5c5d49f8dce18986393e2855008980e311fb48ed8c4494c9328c353",
                "MacAddress": "00:15:5d:fc:4f:8e",
                "IPv4Address": "172.22.106.169/16",
                "IPv6Address": ""
            }
        },
        "Options": {
            "com.docker.network.windowsshim.hnsid": "3007307C-49DC-4DB5-91C8-0E05DAC8E2B6",
            "com.docker.network.windowsshim.networkname": "nat"
        },
        "Labels": {}
    }
]

When I look at my network properties of my host I have :

Name:   vEthernet (nat)
Description:    Hyper-V Virtual Ethernet Adapter #2
Physical address (MAC): 00:15:5d:fc:43:56
Status: Operational
Maximum transmission unit:  1500
IPv4 address:   172.22.96.1/20
IPv6 address:   fe80::d017:d598:692a:2e67%63/64
DNS servers:    fec0:0:0:ffff::1%1, fec0:0:0:ffff::2%1, fec0:0:0:ffff::3%1
Connectivity (IPv4/IPv6):   Disconnected

I am guessing that the NAT in the docker network ls linking to this network hyper v adapter. both have 172.22.96.1 as the IPAddress

connection string:

Server=172.22.96.1;Port=5433;Database=QuickTechAssetManager;Uid=QuickTech;Pwd=password;

SO... when I try to connect from container to host to connect to postgres I get errors even though the I can ping the UP address.

when I look at my host file, host.docker.internal is set to 10.0.0.47 (my wifi connection). Is this "disconnect" part of my network problems.

I have posted a few questions on this and I get one answer and then nothing further. I am would absolutely love to have someone work with me for a bit to resolve this one - what should be minor - issue.

I have modified my pg_hba.conf file, I have done everything I can find...

I will give a phone number or email to anyone who wants to help me solve this. I have been killing myself for over a week and am getting nowhere. I am not even sure is this sort of request is allowed here but I am desperate. I am three months into a project and cant get paid until I get this one minor problem solved.

here is the other question I asked a few days ago: Docker container to connect to Postgres not in docker

rentedtrout@gmail.com for anyone who wants to work with me on this.

Please and thank you in advance.

Chris Dunlop
  • 135
  • 1
  • 13

1 Answers1

0

Have you tried using the host only switch?

docker run --network host "imagename".

This will allow to use the same network as the one in the host i.e if you are able to connect to Postgres from host, then you will be able to connect it from the container as well (with the same ip address).

  • When I try do do that the image starts and immediately stops. I dont know enough about docker but when I create and run the image through VS2019, it works. .NET VS2019's RUN command is life 500 or more characters long and unless I build and run that way it never works, – Chris Dunlop Jul 15 '20 at 17:47
  • Visual studio adds some configuration internally. If the image stops immediately, may the containers port is already used in the host. Remember that --network host will make container to run on the same network as the host. Thus, you wont be able to use the --port switch. – Kshitiz Shakya Jul 15 '20 at 17:53
  • host is the network name for Linux based containers correct? I currently only have access to default switch or NAT for network names (Docker Network LS). Again, when I try to use the Docker --network NAT (which is what my container is currently defaulting to) it will start and immediately stop). I have never been able to get my images to run without building in Vis.Studio. – Chris Dunlop Jul 15 '20 at 18:57
  • Could you share me the docker fie ? If its private , send me a mail at kshitiz.shakya22@gmail.com – Kshitiz Shakya Jul 16 '20 at 01:04