Score:1

I can make my Docker Python HTTPD listen to the external ip but not from outside docker. Why?

om flag

I am not sure if this is relevant, but I am on one of the Oracle Compute instances, and I am using an Ubuntu 22.04 instance. I have opened the right ports so that the server is accessible to the outside world.

Now, here is what is strange: I try the following command.

sudo python3 -m http.server --bind 0.0.0.0 80

And I try to access it from an outside machine with

wget <myip>:80

--2022-11-10 17:39:27--  http://<myip>/
Connecting to   <myip>:80... failed: Connection refused.

Next, I try this:

docker run -p 80:80 -it --entrypoint /bin/sh python:slim
# python3 -m http.server --bind 0.0.0.0 80

Now, surprisingly, wget works.

wget <myip>:80

Connecting to <myip>:80... connected.
HTTP request sent, awaiting response... 200 OK

So, my question is, why am I seeing this? How do I make the Python HTTP server outside the docker listen to the outside world?

Connecting to 168.138.101.164:80... connected. HTTP request sent, awaiting response... 200 OK

For reference, here is my Ingress configuration in the oracle cloud.

My Ingress configuration in Oracle Cloud

I was sent here from stackoverflow.

jabbson avatar
sb flag
when you start the `http.server` with the first command, open another terminal with the same server and run `sudo netstat -tulnp | grep ":80"`. Tell us what you see.
Rahul Gopinath avatar
om flag
This was caused due to `iptables` misconfiguration. Once I flushed the iptables with `iptables -F`, I am able to connect. Should I close this question?
in flag
Either that, because it's trivial and is basically being asked every day. Or you post an answer and accept it.
Score:0
om flag

Answer my question as @Gerald Schneider suggests, because this is a new installation of an Oracle cloud compute instance, so it is possible that others will also hit the same error I hit.

My problem was that the iptables were misconfigured out of the box. I realized the issue after reviewing this answer which pointed out that docker was effectively a new machine with respect to networking. So, after flusing the iptables with iptables -F from the main box, the problem went away.

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.