Network Overview
ipMoodle uses a single user-defined bridge network (moodle-net) to connect all services. This approach provides service discovery, isolation, and simplified communication between containers.
User-defined bridge networks provide automatic DNS resolution, allowing containers to communicate using service names instead of IP addresses.
Network Configuration
The network is defined indocker-compose.yml:
Network Driver: Bridge
The bridge driver creates a private internal network on the Docker host:Isolation
Containers on different networks cannot communicate
DNS Resolution
Service names automatically resolve to container IPs
Port Mapping
Selective port exposure to host system
Subnet Management
Docker automatically manages IP allocation
Service Connections
All four services connect to themoodle-net network:
Network Topology Diagram
Port Mappings
Exposed Ports
Only the web service exposes a port to the host system:| Service | Container Port | Host Port | Protocol | Access |
|---|---|---|---|---|
| web | 80 | 80 | HTTP | Public |
| app | 9000 | - | FastCGI | Internal only |
| db | 5432 | - | PostgreSQL | Internal only |
| cron | - | - | - | No network ports |
The
app and db services use standard ports (9000 for PHP-FPM, 5432 for PostgreSQL) but these are only accessible within the moodle-net network.Port Mapping Syntax
"HOST:CONTAINER"
- HOST: Port on your server (accessible externally)
- CONTAINER: Port inside the Docker container
Service Discovery
Docker’s built-in DNS server enables containers to find each other by service name.DNS Resolution
Each service can be reached using its service name as the hostname:Database
Hostname:
Resolves to: Container IP on moodle-net
Port:
dbResolves to: Container IP on moodle-net
Port:
5432Application
Hostname:
Resolves to: Container IP on moodle-net
Port:
appResolves to: Container IP on moodle-net
Port:
9000Connection Examples
From web to app (Nginx configuration):Communication Patterns
HTTP Request Flow
-
External → Web Server
- Client sends HTTP request to
http://your-server:80 - Request enters the
moodle-netnetwork through the web container
- Client sends HTTP request to
-
Web Server → Application
- Nginx determines request type (static vs. PHP)
- PHP requests proxied to
app:9000via FastCGI protocol - Connection:
web:internal → app:9000
-
Application → Database
- PHP code executes Moodle logic
- Database queries sent to
db:5432 - Connection:
app:internal → db:5432
-
Response Path
- Database returns results to app
- App processes and generates HTML/JSON
- Nginx receives response and sends to client
Cron Communication
The cron container doesn’t handle network requests. Instead, it:- Executes PHP CLI commands directly (no FastCGI)
- Accesses Moodle code via shared filesystem
- Connects to database using
db:5432when needed - Reads/writes to
moodledatavia shared volume
Cron uses the same database connection settings as the app container but executes commands directly through PHP CLI rather than through the web server.
Network Isolation
Internal-Only Services
Services without port mappings are completely isolated from external access:- Database cannot be accessed from internet
- PHP-FPM not exposed to external attacks
- Reduced attack surface
Security Implications
Attack Surface
Only HTTP port 80 is exposed
Database and application layers isolated
Database and application layers isolated
Defense in Depth
Compromised web server cannot directly access host
Network segmentation limits lateral movement
Network segmentation limits lateral movement
Network Performance
Localhost Performance
Containers on the same Docker network communicate through the Linux kernel’s networking stack, providing near-native performance:- Latency: Sub-millisecond between containers
- Throughput: Limited by Docker’s bridge driver (typically 10+ Gbps)
- Overhead: Minimal compared to external network calls
Connection Pooling
PHP-FPM maintains persistent database connections:app and db containers.
Inspecting the Network
View Network Details
- Network subnet and gateway
- Connected containers and their IPs
- Network configuration options
Example Output
Example Output
List Connected Containers
Test Connectivity
From inside a container:Troubleshooting Network Issues
Common Problems
Cannot connect to database
Cannot connect to database
Symptom: Moodle shows database connection errorsChecks:
-
Verify database container is running:
-
Test DNS resolution from app container:
-
Check database is listening:
-
Verify network connectivity:
502 Bad Gateway from Nginx
502 Bad Gateway from Nginx
Symptom: Nginx returns 502 errorChecks:
-
Verify app container is running:
-
Check PHP-FPM is listening on port 9000:
-
Test connectivity from web to app:
-
Check Nginx error logs:
Port 80 already in use
Port 80 already in use
Symptom: Docker Compose fails with “port already allocated”Solution:
-
Find what’s using port 80:
-
Either:
- Stop the conflicting service
- Change ipMoodle’s host port:
Advanced Network Configuration
Custom Subnet
Specify a custom subnet for the network:Static IP Addresses
Assign static IPs to services:Multiple Networks
Connect services to multiple networks for segmentation:Network Security Best Practices
Minimal Exposure
Only expose ports that need external access
Keep database and app ports internal
Keep database and app ports internal
Firewall Rules
Use host firewall to restrict access to port 80
Consider IP whitelisting for admin access
Consider IP whitelisting for admin access
TLS Encryption
Enable HTTPS for all external traffic
See SSL/HTTPS Setup
See SSL/HTTPS Setup
Network Policies
Use Docker network policies for additional isolation
Consider overlay networks for multi-host deployments
Consider overlay networks for multi-host deployments
Next Steps
SSL/HTTPS Configuration
Secure your deployment with TLS encryption
Scaling
Scale services across multiple hosts
Nginx Configuration
Customize web server settings
Troubleshooting
Debug common network issues