Container
Podman
Have an HTTP server which listens on:
0.0.0.0
-> any network interfaceTCP 8080
Make the HTTP server run in a container:
In this model, it is port forwarding from host's TCP 8080 port to the contianer's TCP 8080 port.
The host can query the HTTP server locating in the container and get the response easily by:
There are some cases that the server only listens on the loopback interface, which means localhost.
However, if the server runs in a container, then the server is listening on the container's loopback interface, instead of the host's. Since they are different loopback interfaces, an user on host will be failed to query the server listening on the container's loopback interface.
Here is an example that the HTTP server listens on 127.0.0.1:8080
:
Try to query the HTTP server locating in the container from host:
The query is failed to have a connection. Because, it tried to query an HTTP server listening on host's loopback interface, which does not exist.
There is the option --network=mode
mentioned in Podman's document:
Since the option --network=host
can force the container share the same network stack with the host, the container shares the same loopback interface with the host as well.
Have the HTTP server run in a container with --network=host
:
Try to query the HTTP server locating in the container from host again:
Now, it works!