1. A port on the host can only be bound once
On any operating system (Linux/Windows/macOS), a single port (like 80) can only be assigned to one process at a time.
If you map one container to the host’s port 80 (-p 80:80
), you cannot map another container to the same port—if you try, you’ll get an error like:
textBind for 0.0.0.0:80 failed: port is already allocated.
This means:
- The host’s port 80 can only be used by one container or process at a time.
- Other containers must be assigned different host ports (like 8081, 8082, etc.).
2. Port 80 inside containers is isolated, but on the host it’s shared
Docker containers run in their own network namespaces, so port 80 inside each container is separate.
But when you want to access them from the host, the host’s physical port (like 80) is a shared resource and can only be bound in one place at a time.
3. Solution: Reverse Proxy or Unique Host Port
- Unique Host Port:
Assign each container a different host port (like8081:80
,8082:80
).
Then, use Apache/Nginx/Traefik as a reverse proxy to route traffic to the correct port based on the URL. - Reverse Proxy:
Only the reverse proxy (like Apache/Nginx/Traefik) binds to the host’s port 80.
Proxy rules (based on URL/path/subdomain) forward traffic to the correct container’s internal port 80.
Practical Example
Container Name | Host Port Mapping | Access URL |
---|---|---|
filebrowser_user_12 | 8081:80 | http://localhost:8081 |
filebrowser_user_13 | 8082:80 | http://localhost:8082 |
Or, with Apache/Nginx reverse proxy:
- The host’s port 80 is only used by the proxy.
- URL
/filebrowser/filebrowser_user_12
→ proxy →localhost:8081
- URL
/filebrowser/filebrowser_user_13
→ proxy →localhost:8082
What do you get from docker inspect
?
docker inspect
gives you the container’s IP and port info, but you still cannot open all containers directly on the host’s port 80 due to OS-level restrictions.
You can use a reverse proxy setup to dynamically route traffic (based on info from docker inspect
), but you cannot directly assign the host’s port 80 to multiple containers at once.
Conclusion
- The host’s single port (like 80) can only be assigned to one container or process at a time.
- You cannot bind all containers directly to the host’s port 80.
- Solutions:
- Assign each container a unique host port.
- Or, use a reverse proxy that binds to port 80 and routes traffic to the correct container.
This is a fundamental limitation of how networking and port binding work on all operating systems.