[英]Start Docker container with random host port and return the port to use it elsewhere
I want to start a docker container with ,let's say jenkins as a service, and let docker allocate a random host port. 我想开始一个docker容器,让我们说jenkins作为服务,让docker分配一个随机主机端口。 I know how to do this .
我知道怎么做。
How can I grab the randomly selected port from the running container, or tell docker to return it, in order to use it in the construction of the jenkins github plugin url 如何从正在运行的容器中抓取随机选择的端口,或告诉docker返回它,以便在构建jenkins github插件url时使用它
http://host-ip:random-host-port/web-hook
Once the docker run -P is done, the container is running, with the EXPOSE(d) port mapped to an high port number on the host . 一旦docker运行-P完成,容器就会运行, EXPOSE(d)端口映射到主机上的高端口号 。
To get any information on a running container, use docker inspect
. 要获取有关正在运行的容器的任何信息,请使用
docker inspect
。
If you know the container internal port number (that was then mapped), you can type ( from this comment ): 如果您知道容器内部端口号(然后已映射),则可以键入( 从此注释中 ):
docker inspect --format '{{ (index (index .NetworkSettings.Ports "8080/tcp") 0).HostPort }}' <Container-Name/ID>
The offical Jenkins image uses EXPOSE 8080
. 官方Jenkins图像使用
EXPOSE 8080
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.