Skip to content

Commit 6614082

Browse files
committed
refactor(networking): streamline external access documentation and enhance internal communication examples
1 parent 046412d commit 6614082

File tree

1 file changed

+59
-188
lines changed

1 file changed

+59
-188
lines changed

docs/knowledge-base/destinations/networking.md

Lines changed: 59 additions & 188 deletions
Original file line numberDiff line numberDiff line change
@@ -2,148 +2,81 @@
22

33
Understanding how networking works in Coolify destinations and how to configure network settings for your deployments.
44

5-
## Network Architecture
5+
## External Access
66

7-
### Docker Networks
8-
Each destination creates and manages a Docker network:
9-
- **Network Type**: Bridge (Standalone) or Overlay (Swarm)
10-
- **Network Name**: Unique identifier per destination
11-
- **Isolation**: Resources in different destinations are network-isolated
12-
- **Proxy Integration**: Automatic proxy connection for external access
13-
14-
### Network Flow
15-
```
16-
Internet → Proxy (Traefik/Caddy) → Destination Network → Application Container
17-
```
18-
19-
## Network Types
20-
21-
### Standalone Docker Networks
22-
23-
#### Default Bridge Network
24-
- **Type**: Docker bridge network
25-
- **Scope**: Single server
26-
- **Communication**: Containers can communicate within the network
27-
- **External Access**: Through proxy only
28-
29-
#### Custom Bridge Networks
30-
- **Creation**: Automatically created by Coolify
31-
- **Naming**: Uses destination network identifier
32-
- **Configuration**: Managed by Coolify
33-
- **Connectivity**: Proxy automatically connected
34-
35-
### Docker Swarm Networks
36-
37-
#### Overlay Networks
38-
- **Type**: Docker overlay network
39-
- **Scope**: Across swarm cluster
40-
- **Multi-Host**: Containers communicate across nodes
41-
- **Encryption**: Built-in overlay network encryption
42-
43-
## Proxy Integration
44-
45-
### Automatic Proxy Connection
46-
When a destination is created, Coolify automatically:
7+
#### Through Proxy
478

48-
1. **Creates the Docker network**
49-
2. **Connects the proxy** to the network
50-
3. **Configures routing** for applications
51-
4. **Manages SSL certificates** for domains
9+
All external traffic goes through the proxy:
5210

53-
### Proxy Network Commands
54-
Coolify runs these commands automatically:
55-
```bash
56-
# Create network
57-
docker network create --driver bridge destination-network-name
11+
- **Domain Routing**: Proxy routes based on domain/subdomain
12+
- **SSL Termination**: Proxy handles SSL certificates
13+
- **Load Balancing**: Proxy can load balance to multiple containers
5814

59-
# Connect proxy to network
60-
docker network connect destination-network-name coolify-proxy
61-
```
15+
#### Direct Port Access (Advanced)
6216

63-
## Network Configuration
17+
To bypass the proxy, you can expose ports directly:
6418

65-
### Application Networking
19+
- **Published Ports**: Map container ports to host ports by either adding them into the `Mapped Ports` field in Coolify or defining them in your `docker-compose.y[a]ml` file.
20+
Example:
6621

67-
#### Internal Communication
68-
Applications within the same destination can communicate:
6922
```yaml
70-
# docker-compose.yml example
7123
services:
7224
app:
73-
image: myapp:latest
74-
networks:
75-
- coolify-network
76-
77-
database:
78-
image: postgres:15
79-
networks:
80-
- coolify-network
81-
environment:
82-
- DATABASE_URL=postgresql://user:pass@database:5432/db
25+
image: nginx:latest
26+
ports:
27+
- 8080:80
8328
```
8429
85-
#### Service Discovery
86-
- **Container Names**: Use container names for internal communication
87-
- **DNS Resolution**: Docker provides automatic DNS resolution
88-
- **Port Access**: Use internal ports (not published ports)
89-
90-
### External Access
30+
::: warning CAUTION
31+
The first number represents the host port while the second number is the container port. Make sure to use unique host ports for each service to avoid conflicts.
32+
:::
9133
92-
#### Through Proxy
93-
All external traffic goes through the proxy:
94-
- **Domain Routing**: Proxy routes based on domain/subdomain
95-
- **SSL Termination**: Proxy handles SSL certificates
96-
- **Load Balancing**: Proxy can load balance to multiple containers
97-
98-
#### Direct Port Access (Advanced)
99-
For non-HTTP services, you can expose ports directly:
100-
- **Published Ports**: Map container ports to host ports
10134
- **Firewall Rules**: Configure server firewall accordingly
10235
- **Security**: Consider security implications
10336
10437
<ZoomableImage src="/images/destinations/network-architecture.webp" />
10538
106-
## Network Security
39+
## Internal Communication
10740
108-
### Isolation Between Destinations
109-
- **Default Behavior**: Destinations cannot communicate with each other
110-
- **Network Separation**: Each destination has its own Docker network
111-
- **Container Isolation**: Containers in different destinations are isolated
41+
Resources within the same destination can communicate over the internal Docker network using the **Container Names**, **Network Alias** and **internal Ports** of your Resources.
11242
113-
### Inter-Destination Communication
114-
To enable communication between destinations:
43+
### Example: Connection String Between Apps
11544
116-
#### Option 1: Shared Network
117-
Create a shared network and connect multiple destinations:
118-
```bash
119-
# Create shared network
120-
docker network create shared-network
45+
Consider a Next.js and Express API deployed to the same destination. To connect Next.js to the Express API, we follow these steps:
12146
122-
# Connect destinations to shared network
123-
docker network connect shared-network container1
124-
docker network connect shared-network container2
125-
```
47+
1. **Find the Container Names**: There are multiple ways to find the container names. Here are two common methods:
12648
127-
#### Option 2: External Communication
128-
Use external endpoints through the proxy:
129-
```bash
130-
# Application A calls Application B through external URL
131-
curl https://app-b.example.com/api/endpoint
132-
```
49+
- Go the terminal of your server and run `docker ps` to list all running containers. Look for the names of your applications in the **NAMES** column.
50+
Example output:
13351

134-
#### Option 3: Environment Variables
135-
Pass connection details through environment variables:
136-
```yaml
137-
environment:
138-
- EXTERNAL_API_URL=https://api.example.com
139-
- INTERNAL_DB_HOST=database.internal
14052
```
53+
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
54+
123456789abc nextjs-app:latest "docker-entrypoint.s…" 2 hours ago Up 2 hours 80/tcp my-nextjs-app
55+
abcdef123456 express-api:latest "docker-entrypoint.s…" 2 hours ago Up 2 hours 3001/tcp my-express-api
56+
```
57+
58+
- Navigate to the `Logs` tab of each resource in the Coolify dashboard and copy the container names from the header.
59+
60+
2. **Determine the Internal Port**: Use the port Express listens on internally (e.g., port 3001), not the external published port
61+
62+
3. **Build the Connection String**: `http://[container-name]:[internal-port]`
63+
64+
- Example: `http://my-express-api:3001`
65+
66+
4. **Use in Your App**: Configure your Next.js app to call the Express API using this internal URL instead of the external domain
67+
68+
This same pattern applies to any two applications (databases, APIs, microservices) within the same destination - always use the container name and internal port for communication.
69+
70+
::: info Service Stacks
71+
If you have a Service Stack (deployments using Docker Compose), that needs to connect to a different resource outside of it's stack, you will have to first enable [Connect To Predefined Networks](knowledge-base/docker/compose#connect-to-predefined-networks) in the Service Stack settings.
72+
:::
14173
14274
## Network Troubleshooting
14375
14476
### Common Network Issues
14577
14678
#### Container Cannot Reach External Services
79+
14780
```bash
14881
# Test DNS resolution
14982
docker exec container-name nslookup google.com
@@ -152,10 +85,15 @@ docker exec container-name nslookup google.com
15285
docker exec container-name ping 8.8.8.8
15386
15487
# Check network configuration
155-
docker network inspect destination-network
88+
docker network inspect network-name
15689
```
15790

91+
::: info Note
92+
Make sure to replace `container-name` with the actual name of your container and `network-name` with the docker network name of the destination.
93+
:::
94+
15895
#### Containers Cannot Communicate
96+
15997
```bash
16098
# Check if containers are on same network
16199
docker inspect container1 | grep NetworkMode
@@ -165,7 +103,12 @@ docker inspect container2 | grep NetworkMode
165103
docker exec container1 ping container2
166104
```
167105

106+
::: info Note
107+
Make sure to replace `container1` and `container2` with the actual names of your containers.
108+
:::
109+
168110
#### Proxy Not Routing Traffic
111+
169112
```bash
170113
# Check proxy network connections
171114
docker network ls
@@ -178,6 +121,7 @@ docker logs coolify-proxy
178121
### Network Diagnostics
179122

180123
#### Inspect Network Configuration
124+
181125
```bash
182126
# List all networks
183127
docker network ls
@@ -189,79 +133,6 @@ docker network inspect network-name
189133
docker inspect container-name
190134
```
191135

192-
#### Test Network Connectivity
193-
```bash
194-
# Test from container
195-
docker exec -it container-name sh
196-
ping target-container
197-
curl http://target-container:port
198-
199-
# Test from host
200-
curl http://localhost:published-port
201-
```
202-
203-
## Advanced Network Configuration
204-
205-
### Custom Network Settings
206-
207-
#### Network Aliases
208-
Add network aliases for service discovery:
209-
```yaml
210-
services:
211-
app:
212-
networks:
213-
coolify-network:
214-
aliases:
215-
- api
216-
- backend
217-
```
218-
219-
#### Network Labels
220-
Add labels for network management:
221-
```yaml
222-
networks:
223-
coolify-network:
224-
labels:
225-
- com.coolify.managed=true
226-
- environment=production
227-
```
228-
229-
### Network Performance
230-
231-
#### Network Monitoring
232-
Monitor network performance:
233-
- **Bandwidth Usage**: Track network traffic
234-
- **Latency**: Measure response times
235-
- **Connection Counts**: Monitor active connections
236-
237-
#### Optimization Tips
238-
1. **Minimize Cross-Network Traffic**: Keep related services in same destination
239-
2. **Use Internal URLs**: Avoid external calls for internal services
240-
3. **Connection Pooling**: Use connection pools for database access
241-
4. **Caching**: Implement caching to reduce network calls
242-
243-
## Network Backup and Migration
244-
245-
### Network Configuration Backup
246-
Network settings are preserved in:
247-
- **Destination Configuration**: Stored in Coolify database
248-
- **Docker Network State**: Recreated automatically
249-
- **Proxy Configuration**: Managed by Coolify
250-
251-
### Migration Considerations
252-
When migrating destinations:
253-
1. **Network Names**: May change on new server
254-
2. **IP Addresses**: Will be different on new server
255-
3. **Proxy Configuration**: Automatically updated
256-
4. **Inter-Service Communication**: Uses container names (portable)
257-
258-
## Best Practices
259-
260-
1. **Use Container Names**: For internal service communication
261-
2. **Avoid Hard-Coded IPs**: Use DNS names instead
262-
3. **Network Isolation**: Keep unrelated services in separate destinations
263-
4. **Monitor Network Health**: Implement network health checks
264-
5. **Document Network Architecture**: Maintain network diagrams
265-
6. **Security First**: Follow network security best practices
266-
7. **Test Connectivity**: Regularly test network connectivity
267-
8. **Performance Monitoring**: Monitor network performance metrics
136+
::: info Note
137+
Make sure to replace `network-name` with the actual name of your network and `container-name` with the actual name of your container.
138+
:::

0 commit comments

Comments
 (0)