Netstat 未显示 docker 公开的端口

Netstat not showing ports exposed by docker

出于某种原因 netstat 没有列出 docker 公开的端口。根据建议 here 我对端口 8080 和 5050 使用 EXPOSE。但是其中 none 从主机可见。

Docker文件

...

FROM openjdk:11-jre-slim

COPY --from=build /usr/src/app/api/target/track-metadata-api-*.jar /app/track-metadata-api.jar

WORKDIR /app

EXPOSE 8080 5050

CMD java -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5050 -jar track-metadata-api.jar

docker ps

$ docker ps
CONTAINER ID        IMAGE                           COMMAND                  CREATED             STATUS              PORTS                                            NAMES
a6d3381a992d        track-metadata_track-metadata   "/bin/sh -c 'java -a…"   7 minutes ago       Up 7 minutes        0.0.0.0:5050->5050/tcp, 0.0.0.0:8080->8080/tcp   track-metadata_track-metadata_1

netstat & curl

$ sudo netstat --all | grep 8080 # returns nothing
$ curl http://localhost:8080/v1/track-metadata/filtered
[{"authorName":"AC/DC","duration":208,"id":1,"tags":"#rock","trackName":"Highway to Hell"},{"authorName":"Sum41","duration":209,"id":2,"tags":"#rock","trackName":"War"},{"authorName":"Ziggy Marley","duration":220,"id":3,"tags":"#ragge","trackName":"Beach in Hawaii"}]

Docker & Ubuntu 版本

$ docker --version 
Docker version 18.06.1-ce, build e68fc7a
$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 18.10
Release:    18.10

代号:宇宙

为了公开端口,当 运行 带有 docker run 的图像时,您必须传递 -P(将所有公开的端口发布到随机端口)标志,或者传递 -p标志和指定具体端口,详细here

问题出在 netstat 命令中,在添加 -anp 标志后,列出了端口。

$ sudo netstat -anp | grep 8080
tcp6       0      0 :::8080                 :::*                    LISTEN      16341/docker-proxy