Assign Docker to Physical NIC


Recommended Posts

Good Morning,

 

I believe what I'm asking is possible, but would like to verify and to see the best way to do it.  Basically I would like to assign Docker to one physical NIC on my host, and then the unRaid GUI/VM's to the second physical NIC.

 

Related (but less important), is it possible on a container by container basis to assign what NIC it will go to... similar to the idea of CPU pinning?

 

Thanks!

 

~Spritz

Link to comment

Hi I do something similar,

 

I have 2 nics, eth0 (192.168.1.#) & eth1, eth0 (192.168.2.#) is my normal home network and so I connect to my unraid over this network and then I have eth1, which is connected to a separate router, which is connected to a VPN network.

 

I have plex running on one container which runs hosted over my eth0 network, so my TV's etc can get to it.

 

Then I have transmission and Sickrage running in bridged containers, at boot time I do a little jiggling around to get those 2 containers to send their traffic out over the VPN network.

 

I just switch wireless networks if I want to go out over the VPN or normal network.

 

This is my go file from /boot/config

#!/bin/bash

 

echo "1"

mkdir -p /mnt/btrfs

echo "2"

btrfs device scan

mount -t btrfs /dev/sdj /mnt/btrfs

/etc/rc.d/rc.docker stop

sleep 20

ifconfig eth1 plumb

ifconfig eth1 up

brctl addbr br1

brctl addif br1 eth1

ifconfig br1 inet 192.168.2.100 netmask 255.255.255.0 broadcast 192.168.2.255 up

/etc/rc.d/rc.docker start

 

echo "lets set our container routes"

sleep 60

 

#get the container id of transmission and SAB

Transid=`docker ps | grep transmission | cut -b 1-12`

RAGEid=`docker ps | grep rage| cut -b 1-12`

 

#now find the process id for the container.

TransProcID=`docker inspect -f '{{.State.Pid}}' $Transid`

RAGEProcID=`docker inspect -f '{{.State.Pid}}' $RAGEid`

 

#create the links to allow us to use netns to change variables within the container.

mkdir -p /var/run/netns

ln -s /proc/$TransProcID/ns/net /var/run/netns/$TransProcID

ln -s /proc/$RAGEProcID/ns/net /var/run/netns/$RAGEProcID

 

# use netns to change the default root to use the vpn connection.

ip netns exec $TransProcID route del default gw 192.168.2.100

ip netns exec $TransProcID ifconfig eth0 down

ip netns exec $TransProcID ifconfig eth0 inet 192.168.2.10

ip netns exec $TransProcID route add default gw 192.168.2.1

ip netns exec $TransProcID ifconfig eth0 up

 

ip netns exec $RAGEProcID route del default gw 192.168.2.100

ip netns exec $RAGEProcID ifconfig eth0 down

ip netns exec $RAGEProcID ifconfig eth0 inet 192.168.2.20

ip netns exec $RAGEProcID route add default gw 192.168.2.1

ip netns exec $RAGEProcID ifconfig eth0 up

 

# Start the Management Utility

/usr/local/sbin/emhttp -p 9090 &

 

 

There may be a much cleaner way to do this now, but I set my server up a few years back.

 

Cheers

Link to comment
  • 4 weeks later...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.