4

When I call the command docker ps all my running docker containers are listed. Among other things, the port mappings are displayed in the PORTS column.

I can't figure out what the difference is between this notation: 5432/tcp and that notation: 0.0.0.0:5432->5432/tcp.

zingi
  • 1,141
  • 13
  • 23

1 Answers1

4

5432/tcp means port 5432 is exposed of the container

When you EXPOSE 5432 (or any port you want) in your Dockerfile that’s going to tell Docker that your container’s service can be connected to on port 5432 of the container.

0.0.0.0:5432->5432/tcp means host port 5432 is mapped to container port 5432

When you publish any port, any traffic that comes on the host port will be forwarded to the published container port.

kooskoos
  • 4,622
  • 1
  • 12
  • 29
  • So if there is **5432/tcp** written, it doesn't mean that the host can access it on that port? It just states that a service is available on that port and could be mapped to the host? – zingi Mar 11 '20 at 11:03
  • 2
    Yes, it means that container port 5432 is open for communication, but you can't access it on host port 5432 unless you map it – kooskoos Mar 11 '20 at 11:05