This guide addresses common network errors encountered when running the Three-Tier Task Management Application on clean Linux machines.
Symptoms:
Error: connect ECONNREFUSED 127.0.0.1:3001
Failed to fetch from http://localhost:3001/api/tasks
Symptoms:
Invalid Host header
Cause: React development server rejects requests when using a hostname instead of an IP address for security reasons.
Solutions:
Option 1: Use Production Mode (Recommended)
# Production mode uses nginx and static files, avoiding host header issues
export HOST_IP=your-hostname-or-ip
PRODUCTION=true ./start.shOption 2: Use IP Address Instead of Hostname
# Find your IP address
ip route get 1.1.1.1 | grep -oP 'src \K\S+'
# Use IP instead of hostname
export HOST_IP=192.168.1.100 # Your actual IP
./start.shOption 3: Access via Port Forwarding (Development)
# Start normally and access via localhost
./start.sh
# Then access via: http://localhost:3000 (using SSH port forwarding or similar)Option 4: Development Mode with Warning (Not Recommended for Production)
# Development mode may show warnings but should still work
export HOST_IP=your-hostname
./start.sh
# Access might work despite the warning messageCauses & Solutions:
Ubuntu/Debian:
# Check firewall status
sudo ufw status
# Allow required ports
sudo ufw allow 3000/tcp
sudo ufw allow 3001/tcp
sudo ufw allow 5432/tcp
# Or allow port range
sudo ufw allow 3000:5432/tcpRHEL/CentOS/Fedora:
# Check firewall status
sudo firewall-cmd --state
sudo firewall-cmd --list-all
# Allow ports permanently
sudo firewall-cmd --permanent --add-port=3000/tcp
sudo firewall-cmd --permanent --add-port=3001/tcp
sudo firewall-cmd --permanent --add-port=5432/tcp
sudo firewall-cmd --reload# Check SELinux status
getenforce
# If enforcing, allow Docker containers
sudo setsebool -P container_manage_cgroup on
sudo setsebool -P container_connect_any on
# Or temporarily disable for testing
sudo setenforce 0# Add user to docker group
sudo usermod -aG docker $USER
# Apply group changes without logout
newgrp docker
# Test Docker access
docker psSymptoms:
Error starting userland proxy: listen tcp4 0.0.0.0:3000: bind: address already in use
Solutions:
# Find what's using the port
sudo lsof -i :3000
sudo lsof -i :3001
sudo lsof -i :5432
# Kill the process using the port
sudo kill -9 <PID>
# Or find and kill by port
sudo fuser -k 3000/tcp
sudo fuser -k 3001/tcpSymptoms:
getaddrinfo ENOTFOUND localhost
Solutions:
# Check /etc/hosts file
cat /etc/hosts
# Ensure localhost entries exist
echo "127.0.0.1 localhost" | sudo tee -a /etc/hosts
echo "::1 localhost" | sudo tee -a /etc/hosts
# Test resolution
ping localhost
nslookup localhostSymptoms:
Error response from daemon: network not found
Solutions:
# Clean up Docker networks
docker network prune -f
# Remove specific network if stuck
docker network rm taskapp_network
# Restart Docker daemon
sudo systemctl restart docker
# Recreate containers
docker compose down -v
docker compose up --buildCreate these files for production deployment:
backend/.env.production:
NODE_ENV=production
PORT=3001
DB_HOST=database
DB_PORT=5432
DB_NAME=taskmanager
DB_USER=taskuser
DB_PASSWORD=your_secure_password_here
FRONTEND_URL=http://your-domain.com:3000frontend/.env.production:
REACT_APP_API_URL=http://your-server-ip:3001
HOST=0.0.0.0
PORT=3000Create docker-compose.override.yml:
services:
frontend:
environment:
- HOST=0.0.0.0
extra_hosts:
- "host.docker.internal:host-gateway"
backend:
environment:
- HOST=0.0.0.0
extra_hosts:
- "host.docker.internal:host-gateway"# Make diagnostic script executable
chmod +x diagnose-network.sh
# Run diagnostic
./diagnose-network.sh# Ensure Docker is running
sudo systemctl start docker
sudo systemctl enable docker
# Clean previous containers
docker compose down -v
docker system prune -f
# Check ports are free
sudo lsof -i :3000 -i :3001 -i :5432
# Start application
./start.sh# Check container status
docker compose ps
# Test backend health
curl http://localhost:3001/health
# Test frontend
curl http://localhost:3000
# View logs if issues persist
docker compose logs -f# Inspect Docker network
docker network ls
docker network inspect taskapp_network
# Check container networking
docker compose exec backend ip addr
docker compose exec frontend ip addr
# Test internal connectivity
docker compose exec frontend curl http://backend:3001/health# Backend debugging
docker compose exec backend npm run debug
# Database connectivity test
docker compose exec backend node -e "
const { Pool } = require('pg');
const pool = new Pool({
host: 'database',
port: 5432,
database: 'taskmanager',
user: 'taskuser',
password: 'taskpass123'
});
pool.query('SELECT NOW()').then(res => console.log('DB OK:', res.rows[0])).catch(console.error);
"# Comprehensive logs
docker compose logs --tail=100 -f
# Service-specific logs
docker compose logs backend
docker compose logs frontend
docker compose logs database
# System logs
journalctl -u docker.service --tail=50# Update package list
sudo apt update
# Install required packages
sudo apt install curl netcat-openbsd
# If AppArmor is blocking Docker
sudo aa-status
sudo systemctl reload apparmor# Install required packages
sudo dnf install curl nc
# Docker storage driver issues
sudo systemctl stop docker
sudo rm -rf /var/lib/docker
sudo systemctl start docker# Install Docker (includes compose plugin)
sudo pacman -S docker
# Enable Docker service
sudo systemctl enable docker.service
sudo systemctl start docker.serviceIf nothing works, try this complete reset:
# Stop all containers
docker compose down -v
# Remove all Docker data
docker system prune -a -f
docker volume prune -f
# Reset network
sudo systemctl restart docker
# Disable firewall temporarily for testing
sudo ufw disable # Ubuntu
# OR
sudo systemctl stop firewalld # RHEL
# Start fresh
./start.shIf you're still experiencing issues:
- Run the diagnostic script:
./diagnose-network.sh - Check logs:
docker compose logs -f - Verify system requirements
- Create an issue with the diagnostic output