Ubuntu16.04下Docker部署Tomcat后浏览器无法访问问题求助
Let me walk you through the most likely causes and fixes for this problem— I’ve dealt with similar head-scratchers back when working with Ubuntu 16.04 and Docker, so these are the top things to check:
1. Your browser is running on a different machine than your Ubuntu host
This is the #1 culprit I see. If you’re using a terminal to connect to a remote Ubuntu server (say, from Windows/macOS), typing localhost:8888 in your browser points to your local machine, not the Ubuntu server where Docker is running.
Fix:
- Find your Ubuntu host’s actual network IP (run
ifconfigorip addr showand look for theeth0orens33interface’s inet address, e.g.,192.168.1.100). - Use that IP in your browser:
http://192.168.1.100:8888
2. Ubuntu’s UFW firewall is blocking the port
Ubuntu 16.04 comes with UFW (Uncomplicated Firewall) enabled by default, and it might not allow incoming traffic on port 8888. Even though curl works locally, external requests (like from your browser) get blocked.
Fix:
- Check UFW status:
sudo ufw status - If port 8888 isn’t listed as allowed, add it:
sudo ufw allow 8888/tcp - If you’re still having issues, Docker and UFW have a known compatibility quirk on older Ubuntu versions. Fix this by:
- Editing
/etc/default/ufwand changingDEFAULT_FORWARD_POLICY="DROP"toDEFAULT_FORWARD_POLICY="ACCEPT" - Restart UFW and Docker:
sudo ufw reload sudo systemctl restart docker
- Editing
3. Browser proxy settings are interfering
If your browser uses a proxy server, it might be routing localhost or 127.0.0.1 requests through the proxy, which can’t reach your Ubuntu host’s Docker service.
Fix:
- Disable your browser’s proxy temporarily and try accessing the URL again.
- If you need to keep the proxy enabled, add
localhost,127.0.0.1, and your Ubuntu host’s IP to the proxy’s "bypass list" (sometimes called "no proxy for").
4. Rare: Localhost resolution mismatch (unlikely if curl works)
While curl working makes this unlikely, it’s worth a quick check. If your Ubuntu host’s /etc/hosts file doesn’t map localhost to 127.0.0.1, some tools (including browsers, in rare cases) might fail to resolve it.
Fix:
- Open
/etc/hostsand ensure you have this line:127.0.0.1 localhost - Save the file and try again.
Start with checking if your browser and Ubuntu are on the same machine— that’s almost always the issue when curl works but the browser doesn’t. If that’s not it, move to the firewall and proxy checks.
内容的提问来源于stack exchange,提问作者bx2j

