As a workaround for some operational silliness in a work project, I am trying to:
- Run Service A listening on
localhost:4001
and Service B listeninglocalhost:4002
. - Run Nginx inside a Docker container; internally listening on
0.0.0.0:80
- Set up Docker listening on localhost:80 on the host system, forwarding requests to port 80 in the Nginx container.
- Set up Nginx to forward
localhost:80/a
tolocalhost:4001
, and to forwardlocalhost:80/b
tolocalhost:4002
.
I can write my own nginx.conf
file, but for operational and organizational reasons I am stuck with running Nginx inside Docker.
But is it possible to have the Nginx server running inside a container proxy requests to the loopback device of the host system?
A diagram of what I am attempting to do:
┌──────────────────┐
│ │
│ My web browser │─┐
└──────────────────┘ │
│
┌────────────────────────────────┼───────┐
│ │ │
│ ┌──────────────────────┐ │ │
│ │ │← │ │
┌───┼──────│ Nginx (0.0.0.0:80) │──┘ │
│ ┌─┼──────│ │ │
│ │ │ └──────────────────────┘ │
│ │ │ │
│ │ │ Docker (localhost:80 -> 172.17.0.1:80) │
│ │ └────────────────────────────────────────┘
│ └────────────────────────────┐
│ │
↓│ ↓│
┌───────────────────────────┐ ┌───────────────────────────┐
│ │ │ │
│ Daemon A (localhost:4001) │ │ Daemon B (localhost:4002) │
└───────────────────────────┘ └───────────────────────────┘
localhost
is not accessible from the network, virtual or otherwise.