Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/docker/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何从docker映像中找到要显示的端口?_Docker - Fatal编程技术网

如何从docker映像中找到要显示的端口?

如何从docker映像中找到要显示的端口?,docker,Docker,我有一些码头工人的形象。在我的示例中,它被称为sample\u nginx: $ docker images REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE sample_nginx latest 4b34f8307839 34 hours ago 231.6 MB 我可以运行它docker

我有一些码头工人的形象。在我的示例中,它被称为
sample\u nginx

$ docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             VIRTUAL SIZE
sample_nginx        latest              4b34f8307839        34 hours ago        231.6 MB
我可以运行它
docker run sample\u nginx
,在“端口”栏中,我可以看到从该图像中显示的端口:

$ docker ps -a
CONTAINER ID        IMAGE                 COMMAND                CREATED             STATUS              PORTS               NAMES
650d7a9fe46e        sample_nginx:latest   "/bin/sh -c 'nginx -   3 minutes ago       Up 3 minutes        80/tcp              sleepy_mclean

是否可以在不运行图像的情况下找出图像中显示的端口?

您可以在图像上使用
docker inspect
来查找此端口(以及其他各种有趣的内容):

上面的命令将为您提供大量详细信息。您可以交替地传递a以返回您正在查找的内容,如下所示

$ docker inspect --format='{{.Config.ExposedPorts}}' redis:latest
map[6379/tcp:map[]]

谢谢你的回答,这正是我想要的。
$ docker inspect --format='{{.Config.ExposedPorts}}' redis:latest
map[6379/tcp:map[]]