Hello,
I’m trying to launch a container with a specific IP, or alter it after creation. Is there a way to do this?
For example:
The network settings for default lxdbr0 are ipv4.addres: 10.15.78.1/24
If I create a container with lxc launch ubuntu:16.04 my-container
it may get the IP 10.15.78.119 .
Now I want to change it to 10.15.78.100
I tried these commands, but they didn’t seem to do the trick:
lxc config device add my-container eth0 nic name=eht0 nictype=bridged parent=lxdbr0
lxc config device set my-container eth0 ipv4.address 10.15.78.100
I’ve looked at link and there they discuss changing the network settings themselves and not the containers IP settings.
zoum
December 18, 2018, 12:08pm
2
Which os is your container ?
Depending of Linux version, you can set ip address on configuration files :
/etc/network/interfaces for ubuntu
/etc/sysconfig/network-scripts/if… for centos/redhat
Hi, thanks for the reply @zoum , I’ll look into it. Was actually hoping there was a lxc command that one could run to set the IP or an argument I could add when calling the launch command.
simos
(Simos Xenitellis)
December 18, 2018, 12:56pm
4
See
If running a modern LXD with a LXD managed bridge, then you can just set the ipv4.address property on the network interface of the container.
lxc stop c1
lxc network attach lxdbr0 c1 eth0 eth0
lxc config device set c1 eth0 ipv4.address 10.99.10.42
lxc start c1
on how to set statically the IP address of a container on a managed network using lxc
commands.
To do so, you need to
stop the container
attach the lxdbr0
interface to the container
set the IP address
start the container again.
I got it working
First off, the name was incorrect in my device add command… eht0 instead of eth0 .
And secondly, I had to restart the container.
Thanks for the response @simos . Your message came through just as I figured out what I did wrong, but I bet it would’ve helped me figure it out.
brickcap
(Akshat Jiwan Sharma)
December 18, 2018, 5:46pm
7
Hello Ruan,
Although its not an answer to your question it might be a good idea to put your containers behind a proxy over which you have more control.
I feel it is a little easier to add more ip addresses to the proxy and serve your container apps via them.
Additionally you can take a backup of the container create a new one at some other ip and restore the data.
Hope this helps.
Hi @brickcap , thanks for the suggestion. I will certainly keep it in mind.