Skip to content
This repository was archived by the owner on Sep 1, 2025. It is now read-only.

Commit 4326a83

Browse files
committed
[Fix]: Custom network -> Default Docker network settings
1 parent 07c8ce5 commit 4326a83

File tree

3 files changed

+184
-3
lines changed

3 files changed

+184
-3
lines changed

Dockerfile

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,11 @@ RUN echo '#!/bin/bash' > /usr/local/bin/start-app.sh \
101101
&& echo 'done' >> /usr/local/bin/start-app.sh \
102102
&& echo 'echo "Database connected successfully!"' >> /usr/local/bin/start-app.sh \
103103
&& echo '' >> /usr/local/bin/start-app.sh \
104+
&& echo '# Ensure proper permissions on critical directories' >> /usr/local/bin/start-app.sh \
105+
&& echo 'echo "Fixing permissions..."' >> /usr/local/bin/start-app.sh \
106+
&& echo 'chown -R www-data:www-data /var/www/html/logs /var/www/html/sessions /var/www/html/public/uploads 2>/dev/null || true' >> /usr/local/bin/start-app.sh \
107+
&& echo 'chmod -R 755 /var/www/html/logs /var/www/html/sessions /var/www/html/public/uploads 2>/dev/null || true' >> /usr/local/bin/start-app.sh \
108+
&& echo '' >> /usr/local/bin/start-app.sh \
104109
&& echo '# Run Docker-specific migrations if control script exists' >> /usr/local/bin/start-app.sh \
105110
&& echo 'if [ -f "/var/www/html/control" ]; then' >> /usr/local/bin/start-app.sh \
106111
&& echo ' echo "Running Docker migrations..."' >> /usr/local/bin/start-app.sh \

docker-compose.yml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -202,9 +202,7 @@ services:
202202
networks:
203203
accounting_network:
204204
driver: bridge
205-
ipam:
206-
config:
207-
- subnet: 172.20.0.0/16
205+
name: accounting_panel_network
208206

209207
volumes:
210208
db_data:

network-check.sh

Lines changed: 178 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,178 @@
1+
#!/bin/bash
2+
3+
# PersonalAccounter Docker Network Compatibility Checker
4+
# This script helps diagnose and resolve Docker network conflicts
5+
6+
set -e
7+
8+
# Colors for output
9+
readonly GREEN='\033[0;32m'
10+
readonly BLUE='\033[0;34m'
11+
readonly YELLOW='\033[1;33m'
12+
readonly RED='\033[0;31m'
13+
readonly NC='\033[0m' # No Color
14+
15+
print_header() {
16+
echo -e "${BLUE}╭─────────────────────────────────────────────────────────╮${NC}"
17+
echo -e "${BLUE}│ PersonalAccounter Docker Network Checker │${NC}"
18+
echo -e "${BLUE}╰─────────────────────────────────────────────────────────╯${NC}"
19+
echo ""
20+
}
21+
22+
check_network_conflicts() {
23+
echo -e "${BLUE}🔍 Checking for network conflicts...${NC}"
24+
25+
# Get current subnet from .env
26+
CURRENT_SUBNET=$(grep "DOCKER_SUBNET=" .env 2>/dev/null | cut -d'=' -f2 || echo "172.28.0.0/24")
27+
echo -e "${YELLOW}Current configured subnet: ${CURRENT_SUBNET}${NC}"
28+
29+
# Check if subnet is in use (cross-platform)
30+
if command -v ip >/dev/null 2>&1; then
31+
# Linux
32+
if ip route | grep -q "${CURRENT_SUBNET%/*}"; then
33+
echo -e "${RED}⚠️ Warning: Subnet ${CURRENT_SUBNET} might conflict with existing routes${NC}"
34+
return 1
35+
fi
36+
elif command -v netstat >/dev/null 2>&1; then
37+
# macOS/BSD
38+
if netstat -rn | grep -q "${CURRENT_SUBNET%/*}"; then
39+
echo -e "${RED}⚠️ Warning: Subnet ${CURRENT_SUBNET} might conflict with existing routes${NC}"
40+
return 1
41+
fi
42+
else
43+
echo -e "${YELLOW}💡 Cannot check route conflicts on this system${NC}"
44+
fi
45+
46+
# Check Docker networks
47+
if docker network ls --format "table {{.Name}}\t{{.Driver}}\t{{.Scope}}" | grep -q "accounting"; then
48+
echo -e "${YELLOW}📍 Found existing accounting networks:${NC}"
49+
docker network ls | grep accounting
50+
echo ""
51+
fi
52+
53+
echo -e "${GREEN}✅ No obvious conflicts detected${NC}"
54+
return 0
55+
}
56+
57+
suggest_alternatives() {
58+
echo -e "${BLUE}🛠️ Network Configuration Options:${NC}"
59+
echo ""
60+
echo -e "${GREEN}1. Current Configuration (Customizable):${NC}"
61+
echo " • Subnet: ${DOCKER_SUBNET:-172.28.0.0/24}"
62+
echo " • Gateway: ${DOCKER_GATEWAY:-172.28.0.1}"
63+
echo " • Good for: Specific network requirements"
64+
echo ""
65+
echo -e "${GREEN}2. Auto-Managed (Maximum Compatibility):${NC}"
66+
echo " • Let Docker choose subnet automatically"
67+
echo " • Best for: Avoiding conflicts entirely"
68+
echo ""
69+
echo -e "${GREEN}3. Alternative Subnets:${NC}"
70+
echo " • 172.29.0.0/24 (less common)"
71+
echo " • 172.30.0.0/24 (even less common)"
72+
echo " • 10.99.0.0/24 (private class A)"
73+
echo " • 192.168.99.0/24 (private class C)"
74+
}
75+
76+
fix_conflicts() {
77+
echo -e "${BLUE}🔧 Fixing network conflicts...${NC}"
78+
79+
# Stop containers if running
80+
if docker compose ps -q > /dev/null 2>&1; then
81+
echo -e "${YELLOW}Stopping containers...${NC}"
82+
docker compose down
83+
fi
84+
85+
# Remove existing network if it exists
86+
if docker network ls | grep -q "accounting"; then
87+
echo -e "${YELLOW}Removing existing networks...${NC}"
88+
docker network ls --format "{{.Name}}" | grep accounting | xargs -r docker network rm 2>/dev/null || true
89+
fi
90+
91+
echo -e "${GREEN}✅ Networks cleaned up${NC}"
92+
}
93+
94+
switch_to_auto_managed() {
95+
echo -e "${BLUE}🔄 Switching to auto-managed network...${NC}"
96+
97+
# Create backup
98+
cp docker-compose.yml docker-compose.yml.backup
99+
100+
# Comment out the advanced config and uncomment the simple one
101+
sed -i.tmp '/# Advanced network configuration/,/com.docker.network.driver.mtu: "1500"/s/^/# /' docker-compose.yml
102+
sed -i.tmp '/# Alternative: Simple auto-managed network/,/# *name: accounting_panel_network/s/^# *//' docker-compose.yml
103+
104+
rm docker-compose.yml.tmp
105+
106+
echo -e "${GREEN}✅ Switched to auto-managed network${NC}"
107+
echo -e "${YELLOW}💡 Backup saved as docker-compose.yml.backup${NC}"
108+
}
109+
110+
change_subnet() {
111+
local new_subnet="$1"
112+
local new_gateway="$2"
113+
114+
echo -e "${BLUE}🔄 Changing subnet to ${new_subnet}...${NC}"
115+
116+
# Update .env file
117+
if grep -q "DOCKER_SUBNET=" .env; then
118+
sed -i.tmp "s/DOCKER_SUBNET=.*/DOCKER_SUBNET=${new_subnet}/" .env
119+
else
120+
echo "DOCKER_SUBNET=${new_subnet}" >> .env
121+
fi
122+
123+
if grep -q "DOCKER_GATEWAY=" .env; then
124+
sed -i.tmp "s/DOCKER_GATEWAY=.*/DOCKER_GATEWAY=${new_gateway}/" .env
125+
else
126+
echo "DOCKER_GATEWAY=${new_gateway}" >> .env
127+
fi
128+
129+
rm .env.tmp 2>/dev/null || true
130+
131+
echo -e "${GREEN}✅ Subnet updated in .env file${NC}"
132+
}
133+
134+
main() {
135+
print_header
136+
137+
case "${1:-check}" in
138+
"check")
139+
check_network_conflicts
140+
;;
141+
"suggest")
142+
suggest_alternatives
143+
;;
144+
"fix")
145+
fix_conflicts
146+
;;
147+
"auto")
148+
fix_conflicts
149+
switch_to_auto_managed
150+
echo -e "${GREEN}🚀 Ready to start with auto-managed networks!${NC}"
151+
echo -e "${BLUE}Run: docker compose up -d${NC}"
152+
;;
153+
"subnet")
154+
if [ -z "$2" ] || [ -z "$3" ]; then
155+
echo -e "${RED}Usage: $0 subnet <subnet> <gateway>${NC}"
156+
echo -e "${YELLOW}Example: $0 subnet 172.29.0.0/24 172.29.0.1${NC}"
157+
exit 1
158+
fi
159+
fix_conflicts
160+
change_subnet "$2" "$3"
161+
echo -e "${GREEN}🚀 Ready to start with new subnet!${NC}"
162+
echo -e "${BLUE}Run: docker compose up -d${NC}"
163+
;;
164+
"help"|*)
165+
echo "Usage: $0 [command]"
166+
echo ""
167+
echo "Commands:"
168+
echo " check - Check for network conflicts (default)"
169+
echo " suggest - Show network configuration options"
170+
echo " fix - Clean up existing networks"
171+
echo " auto - Switch to auto-managed networks (maximum compatibility)"
172+
echo " subnet - Change to custom subnet: $0 subnet 172.29.0.0/24 172.29.0.1"
173+
echo " help - Show this help"
174+
;;
175+
esac
176+
}
177+
178+
main "$@"

0 commit comments

Comments
 (0)