About the ip in the docker container?

problem description:
1. I ran my PHP project in the container. At the beginning, the container was bound with 127.0.0.1 8080, but. I accessed through the browser: localhost:8080 did not access the server.
2. Then, in the container, I bind 0. 0. 0. 0. 0. As a result, the server can be accessed through localhost:8080 .
my question is, does the container isolate ip? Through the first step, I feel that the container is isolated from ip, because 127.0.0.1 in the container is isolated from the native 127.0.0.1, so access to the server fails. Therefore, I used 0.0.0.0 in the container. However, for the second step, it seems to be wrong. Because, even if I use 0.0.0.0 in the container, I can access the server in the container with 127.0.0.1 locally. So, is there any quarantine for ip, or not? And how to explain the problems I encountered in the previous two processes?
Screenshot:

1. The services in the container are as follows:

clipboard.png
:

clipboard.png

2:

clipboard.png
:

clipboard.png

I hope seniors can help me answer my questions. Thank you!


four network modes of Docker:

Bridge mode

when the Docker process starts, a virtual bridge named docker0 is created on the host, and the Docker container launched on this host is connected to the virtual bridge. A virtual bridge works like a physical switch so that all containers on the host are connected to a layer 2 network through the switch.

assign an IP from the docker0 subnet to the container and set the IP address of the docker0 as the default gateway of the container. Create a pair of virtual network card veth pair devices on the host. Docker will place one end of the veth pair device in the newly created container and name it eth0 (the container's network card), and the other end in the host, named with a similar name such as vethxxx, and add the network device to the docker0 bridge. You can view it through the brctl show command.

bridge mode is the default network mode of docker. If you don't write the-- net parameter, it is bridge mode. When using docker run-p, docker actually makes DNAT rules in iptables to realize the port forwarding function. You can view it using iptables-t nat-vnL.

bridge mode is shown in the following figure:

clipboard.png

Host

hostNetwork NamespaceNetwork NamespaceIPIP

Host:

clipboard.png

Container

Network Namespace IP IP lo

Container:

clipboard.png

None

noneDockerNetwork NamespaceDockerDockerIPDockerIP

Node:

clipboard.png

Please read more by yourself: http://www.a-site.cn/article/.

Menu