pyveth - veth driver for Docker Engine written in Python
Jacek Kowalski
2026-03-13 69e14cc38a3ac07d8fb95e2edfbc9689084a59cf
Add gw4/gw6 container creation time driver options
2 files modified
42 ■■■■■ changed files
README.md 25 ●●●●● patch | view | raw | blame | history
lib/NetworkDriver.py 17 ●●●●● patch | view | raw | blame | history
README.md
@@ -57,6 +57,31 @@
Disable assignment of IPv6 gateway IP.
## Container creation options
To use these options add `--network name=network_name,driver-opt=option=value,driver-opt=option=value`
to the `docker run` invocation:
```bash
docker run -i -t --rm --network name=test,ip=192.168.1.1,driver-opt=gw4=192.168.0.1,driver-opt=gw6=fe80:: alpine
```
Available options:
`gw4=IP`
`gw6=IP`
Forces assignment of a specified gateway (if one is not provided by the IPAM)
when creating the interface. Useful for [pyipam](https://github.com/jacekkow/docker-plugin-pyipam)
with "ptp=1,nogw=1" options.
Using these would add routes:
```
default via IP dev eth0
IP dev eth0 scope link
```
## Manual packaging
In order to test this module in development environment, you can build it
lib/NetworkDriver.py
@@ -37,7 +37,7 @@
        ip.link('set', index=idx, state='up')
        if 'parent' in network.Options:
            id_parent = ip.link_lookup(ifname=network.Options['parent'])[0]
            print(ip.link("set", index=idx, master=id_parent))
            ip.link("set", index=idx, master=id_parent)
        endpoint.Interface.Peer = ifname1
    return ifname0, ifname1
@@ -157,11 +157,26 @@
            'SrcName': interface,
            'DstPrefix': 'eth',
        },
        'StaticRoutes': [],
    }
    if gw4 is not None:
        result['Gateway'] = gw4.ip.compressed
    if gw6 is not None:
        result['GatewayIPv6'] = gw6.ip.compressed
    gw4 = endpoint.Options.get("gw4", None)
    if gw4 is not None:
        result['StaticRoutes'].append({
            'Destination': gw4 + '/32',
            'RouteType': 1,
        })
        result['Gateway'] = gw4
    gw6 = endpoint.Options.get("gw6", None)
    if gw6 is not None:
        result['StaticRoutes'].append({
            'Destination': gw6 + '/128',
            'RouteType': 1,
        })
        result['GatewayIPv6'] = gw6
    return result