Expose containers by using port mapping
You can securely expose specific containerized applications by mapping network ports to your RHEL containers. This enables communication between isolated services and external clients.
Before you begin
- The
container-toolsmeta-package is installed.
Procedure
-
Run the unpublished container:
# podman run -dt --name=web1 ubi10/httpd-24 -
Run the automatically published container:
# podman run -dt --name=web2 -P ubi10/httpd-24 -
Run the manually published container and publish container port 8080:
# podman run -dt --name=web3 -p 8888:8080 ubi10/httpd-24 -
List all containers:
# podman psCONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES db23e8dabc74 registry.access.redhat.com/ubi10/httpd-24:latest /usr/bin/run-http... 23 seconds ago Up 23 seconds 8080/tcp, 8443/tcp web1 1824b8f0a64b registry.access.redhat.com/ubi10/httpd-24:latest /usr/bin/run-http... 18 seconds ago Up 18 seconds 0.0.0.0:33127->8080/tcp, 0.0.0.0:37679->8443/tcp web2 39de784d917a registry.access.redhat.com/ubi10/httpd-24:latest /usr/bin/run-http... 5 seconds ago Up 5 seconds 0.0.0.0:8888->8080/tcp, 8443/tcp web3You can see that:
- Container
web1has no published ports and can be reached only by container network or a bridge. - Container
web2has automatically mapped ports 33127 and 37679 to publish the application ports 8080 and 8443.The automatic port mapping is possible because the
registry.access.redhat.com/ubi10/httpd-24:latestimage has theEXPOSE 8080andEXPOSE 8443commands in the Containerfile. - Container
web3has a manually published port. The host port 8888 is mapped to the container port 8080.
- Container
-
Display the IP addresses of
web1andweb3containers:# podman inspect --format='{{.NetworkSettings.IPAddress}}' web1# podman inspect --format='{{.NetworkSettings.IPAddress}}' web3 -
Reach
web1container using <IP>:<port> notation:# curl 10.88.0.2:8080... <title>Test Page for the HTTP Server on Red Hat Enterprise Linux</title> ... -
Reach
web2container using localhost:<port> notation:# curl localhost:43595... <title>Test Page for the HTTP Server on Red Hat Enterprise Linux</title> ... -
Reach
web3container using <IP>:<port> notation:# curl 10.88.0.4:8080... <title>Test Page for the HTTP Server on Red Hat Enterprise Linux</title> ...