docker 端口映射 有点蒙圈 谁给解释一下
ringa_lee
ringa_lee 2017-04-25 09:01:39
0
3
2988

docker 端口映射 有点蒙圈 谁给解释一下

ringa_lee
ringa_lee

ringa_lee

reply all(3)
淡淡烟草味

To access each other between containers, you need to use the --link parameter when creating the container, and it is best that the connected container has been named.

docker run --name mysql .......
docker run --name php --link mysql .......
docker run --name nginx --link php .......

When started in this way, you only need to use the corresponding container name in the program to access the corresponding service.
For example fastcgi_pass php:9000;

If the port is exposed to the outside world, you need to pass the -p or -P parameter. It is best to use -p.
docker run --name nginx -p 80:80 -p 443:443 .......
This way the browser can access the web services provided by this server.

大家讲道理

Port mapping:
It is to choose a port of your local machine and map it to a port of your container, so that if a request comes and accesses the mapped port of your local machine, the request will be forwarded to the container. That port relies on the service in the container to handle the request.

Why is there port mapping?
Your local IP is a public IP, such as 1.2.3.4; but the local container IP is a virtual IP, such as 172.17.0.2. The outside world cannot directly access the services of your container. At this time, you can use the services in the container by accessing the port of the local machine.

我想大声告诉你

I don’t know what the so-called “muddle” specifically refers to.
Simply speaking, it is similar to the principle of NAT. If the host network needs to be able to access the services provided by the container, the port of the container needs to be exposed to the host network.
The common syntax is to bring the parameter "-p host_port:container_port" when running "docker run".

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template