search

Home  >  Q&A  >  body text

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

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

ringa_leeringa_lee2770 days ago2966

reply all(3)I'll reply

  • 淡淡烟草味

    淡淡烟草味2017-04-25 09:03:39

    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.

    reply
    0
  • 大家讲道理

    大家讲道理2017-04-25 09:03:39

    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.

    reply
    0
  • 我想大声告诉你

    我想大声告诉你2017-04-25 09:03:39

    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".

    reply
    0
  • Cancelreply