network-programmingpodman

Can't expose port with podman


I am trying to walk through a tutorial that brings up an application in a docker/podman container instance.

I have attempted to use -p port:port and --expose port but neither seems to work.

I've ensured that I see the port in a listen state with ss -an.

I've made sure there isn't anything else trying to bind to that port.

No matter what I do, I can never hit localhost:port or ip_address:port.

I feel like I am fundamentally missing something but don't know where to look next.

Any suggestions for things to try or documentation to review would be appreciated.


Solution

  • Expose: (Reference)

    Expose tells Podman that the container requests that port be open, but does not forward it. All exposed ports will be forwarded to random ports on the host if and only if --publish-all is also specified

    As per Redhat documentation for Containerfile,

    EXPOSE indicates that the container listens on the specified network port at runtime. The EXPOSE instruction defines metadata only; it does not make ports accessible from the host. The -p option in the podman run command exposes container ports from the host.

    To specify Port Number,

    The -p option in the podman run command exposes container ports from the host.

    Example:

    podman run -d -p 8080:80 --name httpd-basic quay.io/httpd-parent:2.4
    

    In above example, Port # 80 is the port number which Container listens/exposes and we can access this from outside the container via Port # 8080