简体   繁体   English

使用随机主机端口启动Docker容器并返回端口以在其他位置使用它

[英]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.

相关问题 GCP 中的 Cloud Run 服务显示“Container failed to start and then listen on the port defined by PORT environment variable” Codeigniter 4 - Cloud Run service in GCP shows “Container failed to start and then listen on the port defined by the PORT environment variable” Codeigniter 4 Github Action 使用环境变量作为端口 - Github Action use environment variable as port Git - 在 github 上远程使用端口 9418 - Git - Use port 9418 for remote on github ssh:连接到主机github.com端口22:将VM复制到另一台主机后,网络无法访问 - ssh: connect to host github.com port 22: Network is unreachable after copying VM to another host machine ssh:连接到主机xxxx端口7999:连接超时-Windows的Git - ssh: connect to host x.x.x.x port 7999: Connection timed out - Git for Windows 如何修复“fatal :unable to look up https (port 9418) (No such host is known)” - How to fix "fatal :unable to look up https (port 9418) (No such host is known) ssh:连接到主机git.ionicjs.com端口22:连接超时 - ssh: connect to host git.ionicjs.com port 22: Connection timed out ssh:连接到主机ssh.github.com端口443:连接被拒绝 - ssh: connect to host ssh.github.com port 443: Connection refused npm 安装错误:ssh:连接到主机 github.com 端口 22:连接超时 - npm install error: ssh: connect to host github.com port 22: Connection timed out 无法连接到github.com端口443:连接被拒绝,无法启动,话语Docker - Failed to connect to github.com port 443: Connection refused, Failed to Bootstrap, Discourse Docker
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM