我如何找出Docker选择了哪个随机端口? [英] How do I find out which random port Docker has chosen?

查看:366
本文介绍了我如何找出Docker选择了哪个随机端口?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我运行了这个

$ docker run -p 8080 --rm my_container 

我想将容器端口8080映射到主机上的某个随机可用端口。但是,如何找出哪个端口呢?

which I guess maps the container port 8080 to some random available port on the host. But how do I find out which port?

推荐答案

您可以使用 docker端口 命令:

You can use the docker port command:

docker port my_container

此命令输出类似于以下内容(带有MySQL映像的示例):

This command output like the following (example with MySQL image):

3306/tcp -> 0.0.0.0:3306

-> 指定容器侧的端口。 -> 之后的值指定主机上的所选端口。

The value before -> specifies the port on the container side. The value after -> specifies the chosen port on the host machine.

您还可以在主机上使用特定端口运行容器(如果可用):

You can also run the container with a specific port on the host machine (if available):

docker run -p "80:8080" --rm my_container

这将在<$ c $上提供以下输出c> docker端口

8080/tcp -> 0.0.0.0:80

这篇关于我如何找出Docker选择了哪个随机端口?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆