Home  >  Q&A  >  body text

nat - 如何用docker制作一个端口转发的镜像?

比如我想把本地的8080端口转发到本地的9090端口,这个如何封装呢?端口都是宿主机之间转发,不需要转发到容器里面去,常用的一个场景就是将内网的数据库端口转发到公网上。

滿天的星座滿天的星座2756 days ago807

reply all(2)I'll reply

  • 習慣沉默

    習慣沉默2017-04-25 09:03:35

    Your description is really hard to understand. The local port is forwarded to the local port. What is this "local" designation, the container or the host?

    For mapping the container port to the host, can't the -p parameter be easily implemented?
    docker run ... -p 13306:3306 mysql
    Doesn’t this map the 3306 port of the container MySQL service to the 13306 port of the host? External access to port 13306 can connect to the database.

    reply
    0
  • PHP中文网

    PHP中文网2017-04-25 09:03:35

    As mentioned above, docker supports port mapping from container to host, using the official -p-Pparameters

    -P         : Publish all exposed ports to the host interfaces
    -p=[]      : Publish a container᾿s port or a range of ports to the host

    For details, please refer to the official website instructions: https://docs.docker.com/engin...

    As for the local-to-local port mapping you described, it should not be a function of Docker.

    reply
    0
  • Cancelreply