You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Ubuntu 16.04下如何从浏览器访问Docker容器内的服务

How to Access Your Dockerized Service from a Browser on Ubuntu 16.04

Hey there! Based on your setup, you’ve got a couple of straightforward ways to reach the service running inside your Docker container from your browser. Let’s break them down:

1. Use Your Local Machine’s Mapped Port (Simplest & Most Reliable)

You already added the -p 3000:3000 flag when starting your container—this does the key work of forwarding traffic from your host’s port 3000 straight to the container’s port 3000.

Just open your browser and navigate to either:

  • http://127.0.0.1:3000
  • http://localhost:3000

This works because Docker automatically routes any requests hitting your host’s 3000 port to the container’s 3000 port where your service is listening.

2. Use the Container’s Direct IP Address

Since you found the container’s IP is 172.17.0.2 via docker inspect, you can also access the service directly using that address. In your browser, go to:
http://172.17.0.2:3000

A quick heads-up: Container IPs from Docker’s default bridge network can change if you stop and restart the container, so this method is less consistent long-term than using the host port mapping.

Quick Troubleshooting If It’s Not Working

If neither method connects, run through these checks:

  • Confirm the container is running: Execute docker ps in your host terminal—you should see your test-env container listed with an Up status.
  • Verify the service is listening inside the container: Re-enter the container with docker exec -it c98d858cb1a4 bash (swap c98d858cb1a4 with your container’s ID/name), then run netstat -tulpn | grep 3000 or ss -tulpn | grep 3000 to check if the service is bound to port 3000.
  • Check your host firewall: If you’re using Ubuntu’s default ufw firewall, make sure port 3000 is allowed with sudo ufw allow 3000.

内容的提问来源于stack exchange,提问作者fwx

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.25 07:57:06