I have created a postgres container from the official posgres image. I am trying to map the port 5432 so I can access the container from my localhost.
If I expose the port through the Dockerfile
, the mapping doesn't happen. Here is my Dockerfile
FROM postgres
EXPOSE 5432:5432
When I build the image and run this, here is what I get when I run docker ps
it see this in the PORTS
column 5432/tcp
When I remove the EXPOSE
from the Dockerfile
and build this
FROM postgres
And then build the image and pass the port on the command line docker run -p 5432:5432 -d postgres
, the port does get mapped. When I run docker ps
I see 0.0.0.0:5432->5432/tcp
in the PORTS
column.
What am I doing wrong? How do I expose the ports in the Dockerfile
in a manner that they will get mapped?