-
-
Save ik5/5ae5a706397b0f4e90df1101b2494f6f to your computer and use it in GitHub Desktop.
Add a VLAN interfaces into Docker from the host machine
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"log" | |
"net" | |
"github.com/milosgajdos83/tenus" | |
) | |
func main() { | |
// CREATE VLAN HOST INTERFACE | |
vlanDocker, err := tenus.NewVlanLinkWithOptions("eth1", tenus.VlanOptions{Dev: "vlanDckr", Id: 20}) | |
if err != nil { | |
log.Fatal(err) | |
} | |
// PASS VLAN INTERFACE TO A RUNNING DOCKER BY PID | |
pid, err := tenus.DockerPidByName("vlandckr", "/var/run/docker.sock") | |
if err != nil { | |
fmt.Println(err) | |
} | |
if err := vlanDocker.SetLinkNetNsPid(pid); err != nil { | |
log.Fatal(err) | |
} | |
// ALLOCATE AND SET IP FOR THE NEW DOCKER INTERFACE | |
vlanDckrIp, vlanDckrIpNet, err := net.ParseCIDR("10.1.41.3/16") | |
if err != nil { | |
log.Fatal(err) | |
} | |
if err := vlanDocker.SetLinkNetInNs(pid, vlanDckrIp, vlanDckrIpNet, nil); err != nil { | |
log.Fatal(err) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment