Cannot open host port 80, but can open docker container port 80

Viewed 31

For some reasones, I need to alternate between the two nginx services on a single Ubuntu host for my web pages, one is host nginx service and the other is docker nginx container.

I installed the docker on a Ubuntu host and run nginx like follwing...

@localhost # docker run -d --name nginx -p 80:80 nginx:alpine

And no problem to see the welcome page of nginx from an external host.

Then I stopped the nginx container.

@localhost # docker stop nginx

Then I activated the nginx service on the Ubuntu host.

@localhost # service nginx start

At this moment, I can see the welcome page of the nginx service in the local of the Ubuntu host.

@localhost # curl localhost
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
<style>
    body {
        width: 35em;
        margin: 0 auto;
        font-family: Tahoma, Verdana, Arial, sans-serif;
    }
</style>
</head>
<body>
<h1>Welcome to nginx!</h1>
<p>If you see this page, the nginx web server is successfully installed and
working. Further configuration is required.</p>

<p>For online documentation and support please refer to
<a href="http://nginx.org/">nginx.org</a>.<br/>
Commercial support is available at
<a href="http://nginx.com/">nginx.com</a>.</p>

<p><em>Thank you for using nginx.</em></p>
</body>
</html>

But I cannot connect to the nginx service from the external.

@external $ curl -v my.webserver.com
*   Trying xxx.xxx.xxx.xxx:80...
* TCP_NODELAY set
* connect to xxx.xxx.xxx.xxx port 80 failed: No route to host
* Failed to connect to my.webserver.com port 80: No route to host
* Closing connection 0
curl: (7) Failed to connect to my.webserver.com port 80: No route to host
@external $ nmap -Pn -p 80 my.webserver.com

PORT   STATE    SERVICE
80/tcp filtered http

Finally, there is no problem on the port 80, but from an external, I can connect to my nginx container but cannot connect to nginx of the host service.

I hope anyone can give me some advice on this.

Following is about the Ubuntu host.

@localhost # cat /etc/os-release
PRETTY_NAME="Ubuntu 22.04.1 LTS"
NAME="Ubuntu"
VERSION_ID="22.04"
VERSION="22.04.1 LTS (Jammy Jellyfish)"
VERSION_CODENAME=jammy
ID=ubuntu
ID_LIKE=debian
HOME_URL="https://www.ubuntu.com/"
SUPPORT_URL="https://help.ubuntu.com/"
BUG_REPORT_URL="https://bugs.launchpad.net/ubuntu/"
PRIVACY_POLICY_URL="https://www.ubuntu.com/legal/terms-and-policies/privacy-policy"
UBUNTU_CODENAME=jammy
0 Answers
Related