MiniBox gives every container a private network namespace connected to the host through a Linux bridge. Outbound traffic is masqueraded through NAT, and inbound traffic is forwarded via iptables DNAT rules and a kernel-bypass TCP proxy. This page explains how the network is set up, how to expose ports, and how to troubleshoot common issues.Documentation Index
Fetch the complete documentation index at: https://mintlify.com/chaitu426/minibox/llms.txt
Use this file to discover all available pages before exploring further.
Architecture overview
CLONE_NEWNET) and a dedicated veth pair connecting it to the bridge.
The minibox0 bridge
SetupBridge() in internal/network/network.go creates a Linux bridge named minibox0 and assigns it the address 172.19.0.1/24, making the host reachable from every container at 172.19.0.1.
The bridge setup also:
- Enables
net.ipv4.ip_forwardandroute_localnetsysctls on the host so packets can traverse bridge → host → internet. - Adds two NAT masquerade rules to iptables
POSTROUTING:- Traffic leaving the
172.19.0.0/24subnet on any interface other thanminibox0is masqueraded (outbound internet access). - Traffic destined for
172.19.0.0/24is also masqueraded (supports localhost DNAT hairpin).
- Traffic leaving the
By default the bridge is created at daemon startup. Set
MINIBOX_BRIDGE_ON_STARTUP=0 to skip bridge creation at startup; minibox0 will then be created lazily the first time a container needs networking. This keeps daemon startup near-instant.Per-container veth pairs
When a container starts,SetupContainerNetwork() runs the following sequence:
Create veth pair
A veth pair is created on the host:
veth-<id> (host side) and vetp-<id> (peer side), where <id> is the first 8 characters of the container ID.Move peer into container netns
vetp-<id> is moved into the container’s network namespace (identified by the child process PID).Configure interfaces inside the namespace
Inside the container’s network namespace:
- Loopback (
lo) is brought up. - The peer veth is renamed to
eth0. - The allocated IP address is assigned to
eth0with a/24prefix. - A default route via
172.19.0.1(the bridge gateway) is added.
Program port-forwarding rules
For each
-p host:container mapping, three iptables rules are installed and a TCP proxy listener is started on the host port:nat/PREROUTING DNAT— rewrites the destination for external traffic arriving onhostPort.nat/OUTPUT DNAT— rewrites the destination for localhost traffic (hairpin).filter/FORWARD ACCEPT— allows forwarded TCP packets to reach the container IP.
IP address allocation
Container IPs are allocated sequentially from172.19.0.2 upward using an atomic counter:
172.19.0.1. The full subnet is 172.19.0.0/24, giving room for up to 253 simultaneous containers before address exhaustion.
Port mapping with -p
Use -p host:container to forward a host port to a container port:
Multiple port mappings
Repeat-p for each additional port:
How the DNAT rules look
For-p 9000:80 where the container IP is 172.19.0.2:
NAT masquerade for outbound traffic
Containers can reach the internet through the host’s default route because of the masquerade rule added tonat/POSTROUTING:
172.19.0.x) with the host’s external IP before the packet leaves the host NIC, and rewrites the reply back to the container.
Network teardown
When a container stops (viaminibox stop, minibox kill, or natural exit), TeardownContainerNetwork() runs automatically:
- Deletes the host-side veth (
veth-<id>). Deleting the host end automatically removes the peer inside the network namespace. - Removes all DNAT/FORWARD iptables rules that were installed for this container’s port mappings.
- Closes and cleans up the TCP proxy listeners for each mapped port.
TeardownBridge() removes the global minibox0 bridge and the masquerade rules from nat/POSTROUTING.
Startup performance flag
Set to
0 to skip bridge creation at daemon startup. The bridge is created lazily the first time a container needs networking. Useful in environments where you want near-instant daemon boot and are running your first container shortly after.Troubleshooting
Stale iptables rules after a crash
Stale iptables rules after a crash
If the daemon crashes or is killed without cleanup, port-mapping rules may linger in iptables. List them and remove manually:Running
minibox system prune after a crash will also clean up orphaned container state, though it does not flush iptables rules automatically.Orphaned veth interfaces
Orphaned veth interfaces
After an unclean shutdown, host-side veth interfaces may remain attached to the bridge:You can also delete the entire bridge and recreate it:
Port already in use
Port already in use
If MiniBox reports Or choose a different host port in your
bind: address already in use when starting a TCP proxy, another process is already listening on the requested host port. Find and stop it:-p flag.Container cannot reach the internet
Container cannot reach the internet
Check that IP forwarding is enabled on the host:If it is MiniBox enables this automatically in
0, enable it:SetupBridge(), but some system configurations reset it.