Matjaž
Matjaž

Reputation: 2115

Netstat not showing ports exposed by docker

For some reason netstat is not listing ports exposed by docker. As suggested here I usedEXPOSE for both ports 8080 and 5050. But none of them is visible from host.

Dockerfile

...

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 version

$ 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

Codename: cosmic

Upvotes: 4

Views: 4168

Answers (2)

Matjaž
Matjaž

Reputation: 2115

Problem was in netstat command, after adding -anp flag, ports are listed.

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

Upvotes: 7

Marcus
Marcus

Reputation: 3524

In order to expose ports you must pass the -P (publish all exposed ports to random ports) flag when running the image with docker run, or alternatively pass the -p flag and specify specific ports, detailed here

Upvotes: 0

Related Questions