Docker port only show the output for the latest container

Hello guys,

I’m trying to get the ports that was mapping for my containers, but it appears that this command only works for a new container (the last one created), and i’d to show my port mappings for my others containers.

This are my containers that are running:

[root@notebook log]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
5bdc6e69e691 debian “/bin/bash” 15 minutes ago Up 15 minutes 80/tcp, 127.0.0.1:8001->444/tcp tadeu_port2
033086b44f99 debian “/bin/bash” 17 minutes ago Up 17 minutes 80/tcp, 0.0.0.0:8000->443/tcp tadeu_port
019fe2f214b6 debian “/bin/bash” 34 minutes ago Up 34 minutes 80/tcp tadeu_teste_commit

Example:

[root@notebook log]# docker port tadeu_port2
444/tcp -> 127.0.0.1:8001

OK, it shows me, but when i tried a container that was created in the past i got no output:

[root@notebook log]# docker port tadeu_teste_commit
[root@notebook log]#

Am i missing something? I’m new at Docker, so any help will be appreciate.

Thanks in advance!

Hello,

Docker port lists the port mappings for a given container. Given the output of your docker ps -a, it seems that the container tadeu_teste_commit has no port mapping ie its private port has not been bound to any host port.
That’s why docker port returns nothing.
On the contrary, you should have this answer for docker port tadeu_port: 443tcp -> 0.0.0.0:8000.

Hello,

It was that i did a “commit” to my container, and this container that was running it has port forwarding, and then i start another one with this image, but it didn’t work out as i expected.

Is there a way to do a “commit” with port/forwardings?

Thanks

I tried to play with the -c option of docker commit to achieve what you wished but with no luck.

$ docker run -d --name nginx-docker -p 9200:80 nginx
$ docker ps |grep nginx-docker
7f5e1f155b1f nginx “nginx -g 'daemon …” 17 minutes ago 443/tcp, 0.0.0.0:9200->80/tcp nginx-docker
$ docker commit -c “EXPOSE 9200:80” nginx-docker nginx-port
$ docker run -d --name nginx-port-1 nginx-port
$ docker ps|grep nginx-port-1
d49f11aa10b1 nginx-port “nginx -g 'daemon …” 22 minutes ago 80/tcp, 443/tcp nginx-port-1

docker commit saves the INTERNALS of the container, not the externals.