All apps · 0 apps
ContainerNetwork-AutoFix
Docker app from ProphetSe7en's Repository
Overview
ContainerNetwork AutoFix (CNAF) - Automatically recreates Docker containers that depend on a master container's network when the master container restarts. Perfect for containers routing through VPN containers like GluetunVPN.
This is the ProphetSe7en fork of buxxdev/containernetwork-autofix with the Unraid template parser rewritten using xmlstarlet. The rewrite fixes three bugs in the upstream sed-based parser:
- Healthchecks broken after rebuild (XML entities not decoded)
- WebUI right-click broken in Unraid GUI (missing net.Unraid.docker.* labels)
- Hardware passthrough lost on rebuild (no Device case in parser)
The fork is a drop-in replacement: same env vars, same mounts, same behavior - only the Repository line needs to change.
When a master container (e.g., VPN) restarts and gets a new container ID, dependent containers using --net=container: lose network connectivity. CNAF automatically detects and recreates those dependent containers.
Features:
- Auto-detects dependent containers
- Preserves container states (running/stopped)
- Smart waiting for VPN establishment
- Automatic log rotation
- Zero manual configuration needed
Readme
View on GitHubContainerNetwork AutoFix (CNAF) — ProphetSe7en fork
Automatically recreates Docker containers that depend on a master container's network when the master container restarts. Designed for Unraid but works on any Docker host.
About this fork: This is a fork of
buxxdev/containernetwork-autofixwith the template parser rewritten usingxmlstarletinstead of hand-rolledsedregex. The rewrite fixes three bugs in the upstream parser:
- Healthchecks broken after rebuild —
<ExtraParams>was not XML-entity-decoded, leaving literal&gt;instead of>in--health-cmdstrings (containers stuckunhealthy).- WebUI right-click broken in Unraid GUI (upstream issue #1) — recreated containers were missing
net.unraid.docker.{webui,shell,support,project}labels.- Hardware passthrough lost on rebuild (upstream issue #2) — the parser had no
Devicecase, so GPU/DVB/USB devices were stripped.The fork keeps the upstream env-var contract intact (
MASTER_CONTAINER,RESTART_WAIT_TIME, etc.) so it works as a drop-in replacement — only the<Repository>line in your Unraid template needs to change. See CHANGELOG.md for full details.
Problem It Solves
When using Docker's --net=container: networking mode (container networking), dependent containers reference the master container by its container ID. When the master container restarts (e.g., after an update), it gets a new container ID, breaking the network connection for all dependent containers.
Common scenario: You have containers routing through a VPN container (like GluetunVPN). When the VPN container updates and restarts, dependent containers lose network connectivity until manually recreated.
CNAF automates that process.
Features
- ✅ Auto-detection - Automatically finds all containers using the master container's network
- ✅ State preservation - Maintains running/stopped state of dependent containers
- ✅ Smart waiting - Waits for VPN/master container to fully establish before recreating dependents
- ✅ Log rotation - Automatic log management to prevent unbounded growth
- ✅ Retry logic - Handles startup race conditions gracefully
- ✅ Zero configuration - Just set the master container name and it handles the rest
Installation
Unraid (Recommended)
- Open Unraid Web UI
- Go to Apps tab
- Search for "ContainerNetwork AutoFix" or "CNAF"
- Click Install
- Configure the master container name (default: GluetunVPN)
- Click Apply
Docker Run (Manual)
docker run -d \
--name='ContainerNetwork-AutoFix' \
--restart=unless-stopped \
-e MASTER_CONTAINER='GluetunVPN' \
-e RESTART_WAIT_TIME='15' \
-v /var/run/docker.sock:/var/run/docker.sock \
-v /boot/config/plugins/dockerMan/templates-user:/templates:ro \
-v /mnt/user/appdata/containernetwork-autofix:/var/log \
ghcr.io/prophetse7en/containernetwork-autofix:latest
Switching from upstream
Already running buxxdev/containernetwork-autofix? Stop the container, change the <Repository> in your Unraid template from buxxdev/containernetwork-autofix:latest to ghcr.io/prophetse7en/containernetwork-autofix:latest, then Apply. All env vars and mounts stay the same — the fork is a drop-in replacement.
Configuration
All configuration is done via environment variables:
| Variable | Default | Description |
|---|---|---|
MASTER_CONTAINER |
GluetunVPN |
Name of the master container to monitor |
RESTART_WAIT_TIME |
15 |
Seconds to wait after master restarts before recreating dependents |
MAX_LOG_LINES |
1000 |
Maximum number of log lines to keep (automatic rotation) |
MAX_RETRIES |
10 |
Number of times to retry finding master container on startup |
RETRY_DELAY |
10 |
Seconds between retry attempts |
RESTART_STOPPED_DEPENDENTS |
false |
When the master restarts, also start dependents that were stopped at that moment. Default keeps the original behavior (stopped dependents stay stopped). Set to true if you want CNAF to bring stopped dependents back up alongside the running ones whenever the master cycles. Note: this only triggers on the master-restart event. CNAF never auto-restarts a container that crashes on its own. |
Volume Mounts
Required (Unraid)
| Volume | Container Path | Description |
|---|---|---|
/var/run/docker.sock |
/var/run/docker.sock |
Access to Docker daemon |
/boot/config/plugins/dockerMan/templates-user |
/templates |
Unraid container templates |
Optional
| Volume | Container Path | Description |
|---|---|---|
/mnt/user/appdata/containernetwork-autofix |
/var/log |
Persistent log storage |
How It Works
- Startup: CNAF starts and waits for the master container to be available
- Detection: Identifies the master container's ID and finds all dependent containers
- Monitoring: Continuously monitors Docker events for master container restarts
- Recreation: When master restarts:
- Waits for configured time (default 15s) for master to stabilize
- Identifies containers still using the old master container ID
- Records each container's state (running/stopped)
- Stops and removes each dependent container
- Recreates from Unraid template
- Restores original state
Use Cases
VPN Containers (Primary Use Case)
Route multiple containers through a VPN:
# qBittorrent routing through GluetunVPN
docker run -d \
--name=qBittorrent \
--net=container:GluetunVPN \
...
When GluetunVPN updates, CNAF automatically recreates qBittorrent with the new network reference.
Supported VPN Containers:
- GluetunVPN
- OpenVPN-Client
- WireGuard
- NordVPN
- Any container using
--net=container:mode
Troubleshooting
"Master container not found"
- Ensure MASTER_CONTAINER name matches exactly (case-sensitive)
- Check master container is running:
docker ps | grep GluetunVPN - Increase MAX_RETRIES or RETRY_DELAY
"Template not found"
- Unraid only: Ensure templates path is correctly mounted
- Check template exists:
ls /boot/config/plugins/dockerMan/templates-user/my-CONTAINERNAME.xml
"No broken containers found"
- Normal if no containers are using the master's network
- Or if dependent containers auto-reconnected
Logs
View real-time logs:
docker logs -f ContainerNetwork-AutoFix
View log file (if using persistent volume):
tail -f /mnt/user/appdata/containernetwork-autofix/containernetwork-autofix.log
Limitations
- Unraid specific: Currently requires Unraid's template system
- Network mode only: Only handles
--net=container:mode - Single master: Monitors one master container at a time
Roadmap
- Support for multiple master containers
Contributing
Issues and pull requests welcome on the fork!
Fork repository: https://github.com/prophetse7en/containernetwork-autofix Upstream repository: https://github.com/buxxdev/containernetwork-autofix
License
MIT License — see LICENSE. Original copyright © buxxdev, fork copyright © ProphetSe7en.
Support
- Fork issues: https://github.com/prophetse7en/containernetwork-autofix/issues
- GHCR: https://github.com/prophetse7en/containernetwork-autofix/pkgs/container/containernetwork-autofix
- Upstream issues: https://github.com/buxxdev/containernetwork-autofix/issues
- Unraid Forums (upstream thread): https://forums.unraid.net/topic/194313-support-containernetwork-autofix-cnaf-auto-fix-vpn-dependent-containers/
Development
The fork is maintained with active AI assistance (Claude, Anthropic) under human direction. Bug-fix decisions, code review, testing on a real Unraid + Docker stack, and releases are done by ProphetSe7en. Issues and PRs go through a human review.
Credits
Original tool created by @buxxdev. Fork maintained by @ProphetSe7en with bug fixes for the Unraid template parser. See CREDITS.md.
ContainerNetwork AutoFix (CNAF) - Keep your container networks healthy, automatically.
Install ContainerNetwork-AutoFix on Unraid in a few clicks.
Find ContainerNetwork-AutoFix in Community Apps on your Unraid server, review the template, and click Install. Unraid handles the Docker app or plugin setup from the published template.
Categories
Related apps
Explore more like this
Explore allDetails
ghcr.io/prophetse7en/containernetwork-autofix:latestRuntime arguments
- Network
bridge- Shell
sh- Privileged
- false
- Extra Params
--restart=unless-stopped -v /var/run/docker.sock:/var/run/docker.sock -v /boot/config/plugins/dockerMan/templates-user:/templates:ro
Template configuration
Optional: Persistent storage for logs
- Target
- /var/log
- Default
- /mnt/user/appdata/containernetwork-autofix
- Value
- /mnt/user/appdata/containernetwork-autofix
Select your VPN/master container from the dropdown. For custom container names, click EDIT and enter the name in the Value field.
- Target
- MASTER_CONTAINER
- Default
- vpn-gateway|GluetunVPN|OpenVPN-Client|WireGuard|NordVPN|binhex-delugevpn|binhex-qbittorrentvpn
- Value
- vpn-gateway
Seconds to wait after master container restarts before recreating dependents (allows VPN to establish)
- Target
- RESTART_WAIT_TIME
- Default
- 15
- Value
- 15
Maximum number of log lines to keep (automatic rotation)
- Target
- MAX_LOG_LINES
- Default
- 1000
- Value
- 1000
Number of times to retry finding master container on startup
- Target
- MAX_RETRIES
- Default
- 10
- Value
- 10
Seconds between retry attempts when finding master container
- Target
- RETRY_DELAY
- Default
- 10
- Value
- 10
When the master restarts, also start dependents that were stopped at that moment. Default false keeps the original behavior. Only triggers on the master-restart event. CNAF never auto-restarts a container that crashes on its own.
- Target
- RESTART_STOPPED_DEPENDENTS
- Default
- false|true
- Value
- false