Docker: MacOSX Expose Container ports to host machine

前端 未结 3 506
误落风尘
误落风尘 2020-12-31 08:41

In my job I working with docker and the option --net=host working like a charm forwarding the docker container ports to the machine. This allows me to adding gr

3条回答
  •  耶瑟儿~
    2020-12-31 09:33

    One workaround, mentioned in "Bind container ports to the host" would be to use -P:

    (or --publish-all=true|false) to docker run which is a blanket operation that identifies every port with an EXPOSE line in the image’s Dockerfile or --expose commandline flag and maps it to a host port somewhere within an ephemeral port range.
    The docker port command then needs to be used to inspect created mapping.

    So if your app can use docker port to retrieve the mapped port, you can add as many containers as you want and get the mapped ports that way (without needed an "explicit -p command for each port").

提交回复
热议问题