Lxc config device add or remove returns an error


(Bruce) #1

I’m getting an odd error message when running lxc config device add or remove commands. This is the error I get on the host

Error: Invalid devices: Not an IP address: localhost

And here are the commands that generate them…

lxc config device remove c1 myport80

lxc config device add c1 myport80 proxy listen=tcp:0.0.0.0:80 connect=tcp:localhost:80

None of the containers are reachable via the web and I just ran a kernel upgrade on Debian 9 earlier today…

Does anyone have any ideas? lxc and lxd are 3.13, installed via snap…


#2

You need to try instead with

lxc config device add c1 myport80 proxy listen=tcp:0.0.0.0:80 connect=tcp:127.0.0.1:80

It is likely that it was allowed in older versions of LXD to put localhost there.
Also, in /snap/core/current/etc/hosts it shows that the snap knows about localhost.


(Bruce) #3

That still returns Error: Invalid devices: Not an IP address: localhost


(Bruce) #4

I’ve been working through this thread but I can’t see anything too dramatic… Running on Debian stretch container networking not working


#5

You cannot get the message Error: Invalid devices: Not an IP address: localhost if you have not specified localhost in the command line.

Can you check again that you have replaced localhost with 127.0.0.1 in the command?


(Bruce) #6

Yeah… this is what I ran…

lxc config device add haproxy myport801 proxy listen=tcp:0.0.0.0:801 connect=tcp:127.0.0.1:801

This error message is something I’ve tracked down as I can’t load any sites in various containers… everything seems to run fine but this is the only error message I’ve been able to find so far…

Also, I can run wget successfully, so outbound stuff is fine but the sites themselves can’t be reached…


(Bruce) #7

Containers all have IP addresses and so on, so I’m at a bit of a loss…

When rebooting having installed the new kernel, I had to re-install zfs to get the containers to start, but this ran fine…

sudo apt -y install linux-headers-$(uname -r)
sudo apt -y install zfsutils-linux zfs-zed
sudo apt -y install spl-dkms
sudo apt -y install zfs-dkms

(Bruce) #8

I’m using the default bridge… lxc network info lxdbr0 shows

Name: lxdbr0
MAC address: fe:19:f7:0d:17:34
MTU: 1500
State: up

Ips:
  inet	10.114.60.1
  inet6	fd42:8037:c8ed:bf9a::1
  inet6	fe80::1856:5cff:feac:c112

Network usage:
  Bytes received: 1.47MB
  Bytes sent: 96.56MB
  Packets received: 18982
  Packets sent: 18882

#9

When you add a device with lxc config device add ..., you give an instruction to LXD to perform this device addition whenever you restart that container.
Therefore, if previously you could run specify localhost in the proxy device, now you cannot.
If since you cannot now, you need to first remove the old proxy device and add a new one.

$ lxc config device list mycontainer
myport80
$ lxc config device remove mycontainer myport80
Device myport80 removed from mycontainer
$ lxc config device add mycontainer myport801 proxy listen=tcp:0.0.0.0:801 connect=tcp:127.0.0.1:801
Device myport801 added to mycontainer
$ lxc config device list mycontainer
myport801
$ 

If you get some error, please paste verbatim the commands and their responses. 

(Bruce) #10

Here are the commands and corresponding errors…

debian@br-lxd:~$ lxc config device list haproxy
myport443
myport80
myport8000
debian@br-lxd:~$ lxc config device remove haproxy myport80
Error: Invalid devices: Not an IP address: localhost
debian@br-lxd:~$ lxc config device add haproxy myport801 proxy listen=tcp:0.0.0.0:801 connect=tcp:127.0.0.1:801
Error: Invalid devices: Not an IP address: localhost

Localhost is not a valid ip address
#11

Ok, this is so straightforward.

What happened is that with older versions of LXD, you could specify localhost but now you can’t.
But what happens if you have some lingering old proxy devices that still mention localhost?
In that case, you are stuck because you cannot perform any other configuration on this container!
LXD will not accept any change to the configuration of the container because after any change, the configuration will still be invalid due to the localhost.

But why can’t you just remove the offending proxy device (with localhost)?
Because it looks like you have two offending proxy devices, and with lxc config device remove ... you can remove only one device at a time. But you cannot remove any of the two, because the other will still be in there.

What you need, is a workaround to sort this issue.
Can you run

debian@br-lxd:~$ lxc config edit haproxy

and edit out both the localhost references in your proxy devices?
Does that command work for you or does LXD complain even with lxc config edit haproxy?


(Bruce) #12

Ok, thank you… I just edited this line connect: tcp:localhost:80 to now read connect: tcp:0.0.0.0:80… there were 3 lines in the config with localhost entries… Everything seems to be working now!