edgararroyo
Posts: 17
Joined: Mon Aug 13, 2012 5:39 am

raspbian and docker

Wed Sep 11, 2019 3:34 am

I am trying to run alpine docker and need to assign the local interface eth0.0 which is a macvlan to the docker, but getting error:

Code: Select all

docker: Error response from daemon: network eth0.0 not found.

How can I accomplish this?

Thanks!

epoch1970
Posts: 5903
Joined: Thu May 05, 2016 9:33 am
Location: Paris, France

Re: raspbian and docker

Wed Sep 11, 2019 9:14 am

https://docs.docker.com/network/macvlan/
Let it create the network and interfaces for you.
By specifying eth0.0 Docker understands VLAN 0 on interface eth0. VLAN 0 is not a valid ID for you to use.
Do you need to map the macvlan network to a VLAN at all?
"S'il n'y a pas de solution, c'est qu'il n'y a pas de problème." Les Shadoks, J. Rouxel

edgararroyo
Posts: 17
Joined: Mon Aug 13, 2012 5:39 am

Re: raspbian and docker

Thu Sep 12, 2019 3:00 pm

@epoch1970, I actually solved this already. Here is what I did:

Code: Select all

#!/bin/sh

# Get IPv4 for Gateway, Subnet Mask and IP Addresses
while [ -z "$ip4" ]
do
ip4="$(ip -o -4 addr list eth0 | awk '{print $4}' | cut -d. -f1,2,3)"
done

# Stop running containers
docker kill alpine1
docker kill alpine2
docker kill alpine3

# Remove containers
docker rm alpine1
docker rm alpine2
docker rm alpine3

# Remove docker network
docker network rm eth0

# Create docker network
docker network create -d macvlan --subnet="$ip4.0/24" --gateway="$ip4.1" -o parent=eth0 -o macvlan_mode=bridge eth0

# Start dockers
docker run -d --name='alpine1' --net='eth0' --ip="$ip4.101" 'alpine' tail -f /dev/null
docker run -d --name='alpine2' --net='eth0' --ip="$ip4.102" 'alpine' tail -f /dev/null
docker run -d --name='alpine3' --net='eth0' --ip="$ip4.103" 'alpine' tail -f /dev/null

3 alpine dockers running with their own IP addresses :D

And to connect to them, you just run a shell.

Code: Select all

docker exec -ti alpine# /bin/sh

Where # is between 1 and 3

Now my hurdle is making these interfaces get IP, gateway, subnet and dns via DHCP, but there is no plugin yet. Need DHCP because this only works if the subnet is 0/24 and gateway is 1 and IP addresses 101 thru 103 are not being used.

Cheers!

epoch1970
Posts: 5903
Joined: Thu May 05, 2016 9:33 am
Location: Paris, France

Re: raspbian and docker

Sat Sep 14, 2019 1:04 pm

edgararroyo wrote:
Thu Sep 12, 2019 3:00 pm
Now my hurdle is making these interfaces get IP, gateway, subnet and dns via DHCP, but there is no plugin yet. Need DHCP because this only works if the subnet is 0/24 and gateway is 1 and IP addresses 101 thru 103 are not being used.
Docker (and SDN in general) is not friendly with DHCP and its broadcasts.

Do you mean to say you want your containers to get an address on the local network, as if they were bridged VMs?
If so, use host networking in docker, and use a bridge in the host. Docker will use veth pairs to connect to the bridge, as by default.
If that doesn't do it, you'll probably need to run the containers in privileged mode, or specify something like NET_ADMIN_CAP when running the container. By default IIRC the containers won't even let you run an "ifconfig" command.

All the information is judiciously scattered all over Docker's docs. If you read blogs instead, beware of the document's write up date. Docker is a bit of a moving target...

(Also, if you see your containers as VMs, "you're holding it wrong". Docker's vision is "one process per container", it doesn't naturally fits "fat" containers.)
"S'il n'y a pas de solution, c'est qu'il n'y a pas de problème." Les Shadoks, J. Rouxel

edgararroyo
Posts: 17
Joined: Mon Aug 13, 2012 5:39 am

Re: raspbian and docker

Sat Sep 14, 2019 3:42 pm

Thank you for your reply.

I guess I am ok with not getting IP address from DHCP. What would help is somehow getting the existing local eth0 subnet mask and gateway differently so I can use it on any netowrk. Right now I am assuming it's .0/24 subnet and .1 gateway... I guess what I need is how to find out the subnet mask and gateway of eth0 so I can create my docker network using these parameters. OR just leave it as-is and manually edit the script if used on a different network.

epoch1970
Posts: 5903
Joined: Thu May 05, 2016 9:33 am
Location: Paris, France

Re: raspbian and docker

Sat Sep 14, 2019 4:41 pm

The standard Docker solution is a bridge with routing/NAT, that works everywhere.
If you nuke the bridge definition in /etc/docker/daemon.json, next time the machine boots Docker automatically creates its default bridge and chooses an IP range that does not clash with the host's LAN. If you keep the file as is, move the host to another network, I don't think it tries redefining the bridge parameters in case of clash.

You could also play with "network=none" and send host interfaces one by one in containers (network=host sends the whole lot.) Pipework does that, it juggles with network namespaces in the host for you, which is nice.
Pipework is getting old, not all options will still work. But last time I tried, exporting a single host interface to a container was possible and working fine...
Not standard/recommended practice at all!
"S'il n'y a pas de solution, c'est qu'il n'y a pas de problème." Les Shadoks, J. Rouxel

edgararroyo
Posts: 17
Joined: Mon Aug 13, 2012 5:39 am

Re: raspbian and docker

Sat Sep 14, 2019 4:58 pm

That won't work for me, I need to host services, that's why I needed DHCP. But if I can get the subnet mask and gateway I can assign IP address depending on the subnet mask and gateway.

This is to host multiple instances of a service that use the same port, so I need the dockers to have their own IP address.

epoch1970
Posts: 5903
Joined: Thu May 05, 2016 9:33 am
Location: Paris, France

Re: raspbian and docker

Sat Sep 14, 2019 5:40 pm

manual macvlan creation + networking=none + pipework will work with DHCP.

To assign IPs from the network you need the IP parameters but also to have some authority on it. Otherwise one day you might assign an address that is reserved to some special use, and the firewall will block or an alarm will ring somewhere...
"S'il n'y a pas de solution, c'est qu'il n'y a pas de problème." Les Shadoks, J. Rouxel

edgararroyo
Posts: 17
Joined: Mon Aug 13, 2012 5:39 am

Re: raspbian and docker

Sat Sep 14, 2019 6:04 pm

epoch1970 wrote:
Sat Sep 14, 2019 5:40 pm
manual macvlan creation + networking=none + pipework will work with DHCP.

To assign IPs from the network you need the IP parameters but also to have some authority on it. Otherwise one day you might assign an address that is reserved to some special use, and the firewall will block or an alarm will ring somewhere...
Ok thanks. I started using macvlan but never got to using pipework because I decided to use macvlan on docker LOL

I was using:

Code: Select all

ip link add link eth0 name eth1 address xx:xx:xx:xx:xx:xx type macvlan
And both eth0 and eth1 were getting their own IP address.

So can you give me a crash course in how to use pipework for my scenario? I'm a quick learner.

epoch1970
Posts: 5903
Joined: Thu May 05, 2016 9:33 am
Location: Paris, France

Re: raspbian and docker

Sun Sep 15, 2019 1:22 pm

Frankly, no.
I think I read the readme and especially this and from there a version with DHCP in the container wasn't far.
I don't remember the details, it must have been easy.
"S'il n'y a pas de solution, c'est qu'il n'y a pas de problème." Les Shadoks, J. Rouxel

edgararroyo
Posts: 17
Joined: Mon Aug 13, 2012 5:39 am

Re: raspbian and docker

Sun Sep 15, 2019 8:07 pm

epoch1970 wrote:
Sun Sep 15, 2019 1:22 pm
Frankly, no.
I think I read the readme and especially this and from there a version with DHCP in the container wasn't far.
I don't remember the details, it must have been easy.
Ok, thanks. Will look into it.

Return to “Troubleshooting”