⚡ ~/naveed Interview Prep
⚡ Portfolio Home 👤 About Naveed Bio & Credentials 📫 Contact Naveed Get In Touch ✍️ Engineering Blog Deep Dives 🎯 Interview Hub 1,000+ Scenarios ☸️ Kubernetes Mastery Hub 24 Modules 🎮 DevOps Arcade & Quizzes Subnet Blitz ⚡ 🗺️ DevOps Roadmaps PDFs & Guides 🤖 Morpheus Analysis AI Quant ↗ 🛠️ Developer Tools Utilities 🧪 Labs & Experiments 📄 Interactive CV & Certs 🔗 All Links & Socials ⚡ Join The Dispatch (Weekly SRE Newsletter) →
← Back to All Docker & Containers Interview Questions Scenario 107 of 159 in Docker & Containers
Intermediate / Senior DevOps Docker Container Networking & Troubleshooting Diagnostic Playbook
🎯 Target Role / Context: DevOps Engineer Infrastructure Drill

Q: Your Docker container is running, but the application is not accessible from the host or network. Where would you start?

A Docker container is reported as Up and running, but external HTTP requests fail with Connection Refused or Timeout. Diagnosing port mappings, 0.0.0.0 vs 127.0.0.1 bindings, and Docker bridge iptables.

#Docker #Networking #Port Forwarding #iptables #Troubleshooting
🎙️ Candidate Opening & Architectural Context
"When 'docker ps' shows a container in the 'Up' state, it only means the primary process (PID 1) has not exited. An inaccessible container usually stems from network interface binding issues, missing port publication, or host firewall filtering."
Advertisement
⚡ Recommended Practice Lab

Want to master this scenario in a live sandbox? KodeKloud's Docker Certified Associate (DCA) Hands-On Lab Course covers this exact problem with hands-on terminal drills.

🛠️ Production Runbook & Step-by-Step Resolution

Direct Answer: When 'docker ps' shows a container in the 'Up' state, it only means the primary process (PID 1) has not exited. An inaccessible container usually stems from network interface binding issues, missing port publication, or host firewall filtering.

1

Inspect Host Port Publishing vs. Container Expose

Check 'docker ps' PORTS column. An EXPOSE 80 in a Dockerfile does not publish the port to the host. You must explicitly publish it using -p : or --publish-all.

# Check if port is published:
docker ps --format "table {{.Names}}	{{.Status}}	{{.Ports}}"
# Output showing '80/tcp' means NOT published to host!
# Output showing '0.0.0.0:8080->80/tcp' means correctly published.
2

Check Interface Binding Inside the Container: 0.0.0.0 vs 127.0.0.1

The most common architectural bug: the application server inside the container binds to 'localhost' (127.0.0.1). Because each container has its own network namespace, 127.0.0.1 only accepts traffic from inside the container. It MUST bind to 0.0.0.0 (all interfaces) to receive traffic forwarded from the host.

docker exec -it <container_name> netstat -tlpn
# Or using ss:
docker exec -it <container_name> ss -tlpn
# Look for 0.0.0.0:<port>, NOT 127.0.0.1:<port>
Advertisement
3

Test Local Connectivity Inside the Container

Determine if the application itself is responsive or crashed on an internal thread lock.

docker exec -it <container_name> curl -v http://localhost:<port>/health
4

Verify Host Firewall & Docker iptables Forwarding

Linux firewalls (UFW, firewalld) can conflict with Docker's native iptables chains. If UFW has a default DROP forward policy, Docker NAT traffic from external clients will be dropped.

sudo iptables -L DOCKER -n -v
sudo ufw status verbose
5

Check Container Logs & Resource Exhaustion

Check if the process is stuck in a deadlock, out of memory, or stalled on an unreached database connection.

docker logs <container_name> --tail=50
docker stats <container_name> --no-stream
💡 The Senior SRE Gold Nugget (Key Architectural Takeaway)
"The #1 cause of an inaccessible running Docker container is binding to 127.0.0.1 instead of 0.0.0.0 inside the container, followed by forgetting host port publication (-p <host>:<container>)."
⚡ 60-Second Elevator Pitch Talking Points
  • Start with 'docker ps' to verify port publication: ensure you see '0.0.0.0:host_port->container_port', not just an unpublished '80/tcp'.
  • Check the application binding interface inside the container: the app must bind to 0.0.0.0, not 127.0.0.1, to receive bridged traffic.
  • Exec into the container and curl localhost:port to isolate whether the app itself is healthy or hung.
  • Inspect host iptables and firewall (UFW/firewalld) to ensure the DOCKER chain allows packet forwarding.
  • Review container stdout/stderr logs to verify that the application completed its startup sequence and is listening.
⛔ Critical Candidate Mistakes to Avoid in This Scenario

Senior hiring managers and bar raisers evaluate how you prioritize during outages. Avoid these common anti-patterns:

  1. Structuring Dockerfile instructions inefficiently by copying app source before package manifests when configuring Docker Container 'Up' Copying code before package manifests (package.json, go.mod, requirements.txt) invalidates the build cache on every commit, forcing slow full reinstalls.
  2. Neglecting the PID 1 process reap problem and omitting proper SIGTERM signal forwarding when configuring Docker Container 'Up' If an application runs as PID 1 without an init system (like tini), it fails to reap zombie child processes and ignores SIGTERM signals, causing unclean 10s timeouts.
  3. Assembling single-stage images containing compilers, build SDKs, and header files in production when configuring Docker Container 'Up' Single-stage builds bloat image size by gigabytes and expose extensive package vulnerabilities; multi-stage builds isolate artifacts into minimal distroless images.
  4. Confusing container port forwarding on bridge networks with unisolated host networking mode when configuring Docker Container 'Up' Bridge networking utilizes iptables NAT translations which add latency overhead, whereas host networking bypasses the network namespace entirely.
Advertisement
Want more Docker & Containers scenarios?
Explore our complete collection of scenario-based Docker & Containers interview runbooks.
Browse All Docker & Containers Questions →