A developer reports that a container running a custom web application is failing to start on a Red Hat Enterprise Linux 8 host. The container image is built from a Dockerfile that uses 'EXPOSE 8080'. The host firewall is enabled. Which action is most likely required to allow external access to the application?
Trap 1: Open port 8080 in the host firewall using firewall-cmd.
Running firewall-cmd --add-port=8080/tcp only adds an allow rule to the host's firewalld zone, permitting inbound connections to the host's own port 8080. It does not create any mapping between that host port and the container's network namespace; the container still listens on an isolated bridge IP (e.g., 172.17.0.2) that the host firewall cannot redirect to. Since no docker port publishing exists, traffic allowed by the firewall has no destination inside the container, so the developer's reported connectivity issue remains completely unresolved.
Trap 2: Disable the host firewall to allow all incoming traffic.
Disabling the host firewall (e.g., systemctl stop firewalld) removes all packet filtering at the host level, but the container's port remains unpublished; no DNAT rule or proxy maps host port 8080 to the container's bridge IP. Even with the firewall off, inbound packets on host port 8080 have no forwarding chain to the container's internal network address, so the custom web app stays unreachable. Furthermore, this disables protection for the entire host, leaving every open service exposed to the network — a catastrophic security choice that a Red Hat administrator should never make for any environment.
Trap 3: Ensure the container image includes an EXPOSE instruction for port…
The EXPOSE instruction in a Dockerfile is purely declarative metadata; it records which ports the application intends to listen on and is used by docker run -P to publish all exposed ports to random host ports. By itself, EXPOSE does not create any port binding, iptables rule, or userland proxy, so a container started without -p or -P will not accept traffic from the host on port 8080. Adding EXPOSE to the image would only help if the container were later started with -P, which still wouldn't yield a predictable host port — and rebuilding the image changes nothing about the current runtime network configuration.
- A
Start the container with the '-p 8080:8080' option to publish the port.
The -p 8080:8080 flag publishes the container's TCP port 8080 to the same port on the host, creating an explicit mapping on Docker's default bridge network. This causes Docker to install an iptables DNAT rule and start a userland proxy (docker-proxy) that forwards incoming host traffic on port 8080 to the container's internal IP address. Without this flag, the container runs in its own network namespace and no host port is bound, so the web app is unreachable from the host or any external client.
- B
Open port 8080 in the host firewall using firewall-cmd.
Why wrong: Running firewall-cmd --add-port=8080/tcp only adds an allow rule to the host's firewalld zone, permitting inbound connections to the host's own port 8080. It does not create any mapping between that host port and the container's network namespace; the container still listens on an isolated bridge IP (e.g., 172.17.0.2) that the host firewall cannot redirect to. Since no docker port publishing exists, traffic allowed by the firewall has no destination inside the container, so the developer's reported connectivity issue remains completely unresolved.
- C
Disable the host firewall to allow all incoming traffic.
Why wrong: Disabling the host firewall (e.g., systemctl stop firewalld) removes all packet filtering at the host level, but the container's port remains unpublished; no DNAT rule or proxy maps host port 8080 to the container's bridge IP. Even with the firewall off, inbound packets on host port 8080 have no forwarding chain to the container's internal network address, so the custom web app stays unreachable. Furthermore, this disables protection for the entire host, leaving every open service exposed to the network — a catastrophic security choice that a Red Hat administrator should never make for any environment.
- D
Ensure the container image includes an EXPOSE instruction for port 8080.
Why wrong: The EXPOSE instruction in a Dockerfile is purely declarative metadata; it records which ports the application intends to listen on and is used by docker run -P to publish all exposed ports to random host ports. By itself, EXPOSE does not create any port binding, iptables rule, or userland proxy, so a container started without -p or -P will not accept traffic from the host on port 8080. Adding EXPOSE to the image would only help if the container were later started with -P, which still wouldn't yield a predictable host port — and rebuilding the image changes nothing about the current runtime network configuration.