0

I'm trying to host a Linux Mint container that starts a simple Angular server and listens on port 4200. I'm in a very tight environment, with no admin authority on a Windows machine. Running

wget localhost:4200

gives me an index.html file. The contents don't matter, so long as it's able to reach the Angular server (ok, the Angular code hosted on a NodeJS server for those that are pendantic). So, it works in the container.

The port is remapped on the host to port 80.

docker ps -a --format "table {{.ID}}\t{{.Ports}}"
CONTAINER ID   PORTS
44619004abe5   127.0.0.1:80->4200/tcp

On the host, Windows netstat reports (irrelevant items omitted):

  Proto  Local Address          Foreign Address        State
  TCP    127.0.0.1:80           0.0.0.0:0              LISTENING

So for some reason, Docker claims it's routing port 80 into the container's port 4200 yet Windows redirects things to whatever port 0 is.

Trying wget on a known bad port to see the error:

>wget localhost:4299
--2022-05-13 19:32:58--  http://localhost:4299/
Resolving localhost (localhost)... ::1, 127.0.0.1
Connecting to localhost (localhost)|::1|:4299... failed: Bad file descriptor.

Trying wget on what should be a good port:

wget http://localhost:80
--2022-05-13 19:34:22--  http://localhost/
Resolving localhost (localhost)... ::1, 127.0.0.1
Connecting to localhost (localhost)|::1|:80... failed: Bad file descriptor.
Connecting to localhost (localhost)|127.0.0.1|:80... connected.
HTTP request sent, awaiting response... No data received.
docker inspect 44619
"NetworkSettings": {
            "Bridge": "",
            "SandboxID": "e9505e8ca350eb07fdefd082ea4530885fc602539004b4ca5a6f552e876940e9",
            "HairpinMode": false,
            "LinkLocalIPv6Address": "",
            "LinkLocalIPv6PrefixLen": 0,
            "Ports": {
                "4200/tcp": [
                    {
                        "HostIp": "127.0.0.1",
                        "HostPort": "80"
                    }
                ]
            },
            "SandboxKey": "/var/run/docker/netns/e9505e8ca350",
            "SecondaryIPAddresses": null,
            "SecondaryIPv6Addresses": null,
            "EndpointID": "",
            "Gateway": "",
            "GlobalIPv6Address": "",
            "GlobalIPv6PrefixLen": 0,
            "IPAddress": "",
            "IPPrefixLen": 0,
            "IPv6Gateway": "",
            "MacAddress": "",
            "Networks": {
                "docker-files_default": {
                    "IPAMConfig": null,
                    "Links": null,
                    "Aliases": [
                        "geneticist_app",
                        "44619004abe5"
                    ],
                    "NetworkID": "302510faf209d6eae4da6d0c5951b63f7821d521707d6d2f9ecca5e7dbda4330",
                    "EndpointID": "e761a8da5c6d88d9f86bb05bc3c794a92dbe37e5d62bc11c5440111be5fa3c0e",
                    "Gateway": "172.23.0.1",
                    "IPAddress": "172.23.0.2",
                    "IPPrefixLen": 16,
                    "IPv6Gateway": "",
                    "GlobalIPv6Address": "",
                    "GlobalIPv6PrefixLen": 0,
                    "MacAddress": "02:42:ac:17:00:02",
                    "DriverOpts": null
                }
            }
}

Woodsman
  • 901
  • 21
  • 61
  • 1
    Do you happen to have your server listening on host `127.0.0.1` ? If so, that's your issue. Also, if by "whatever port 0 is" you're referring to the foreign address, that doesn't work the way you think. – Ryan May 14 '22 at 03:30
  • @Ryan I thought the Angular server would be within the container, and since that lived on the windows machine, it would be on that one as well. It is a server within a server. On each server, the host could be referred to by 127.0.0.1. What do I not understand? – Woodsman May 14 '22 at 14:05
  • @Ryan I wasn't sure what port 0 meant. I *thought* there'd be a listener port of 80 on the host and a foreign port of whatever the docker container opened. The 0 looked strange, so I mentioned it. – Woodsman May 14 '22 at 14:08
  • Well, it's actually a containerized server, rather than a "server within a server". The Docker container is a layer on top of the host with its own network and more. That said, going back to my first point: A common mistake is to have a server listening on a port of IP `127.0.0.1` inside of a container. When configured this way, the server is inaccessible from the host. Instead, it should be listening on the desired port of IP 0.0.0.0 (typically the default). [Question on this topic](https://stackoverflow.com/q/59179831) – Ryan May 14 '22 at 18:29
  • Also, [wikipedia](https://en.wikipedia.org/wiki/0.0.0.0) has good info on the `0.0.0.0` meta-address. – Ryan May 14 '22 at 18:38
  • I think the "own network" thing applies if the container networking isn't bridge host mode. After you mentioned this, I tried host and could not get any farther. An IT support person claimed they blocked port redirects so no one could start a server in a container (under any port), and have it work in the host (under any port). Another colleague of mine claims that he can get it to work though, so I wasn't sure. I either want to force docker to work as I intend, or prove it's the strict IT admin. – Woodsman May 15 '22 at 03:35
  • @Ryan Thanks for your comments btw. I specified ng serve --host=0.0.0.0. Now it listens on some completely different IP address. I don't see the IP address in the container's ifconfig, nor anywhere in the docker network listing. Further, that IP address was listed as a foreign address in netstat. Very confusing. I wish I could just list a server and expose it to my host. – Woodsman May 15 '22 at 03:58

0 Answers0