Lxc Container

Lxc Container

lxc-create -t download -n my-container

The download template will show you a list of distributions, versions and architectures to choose from.
A good example would be “ubuntu”, “trusty” (14.04 LTS) and “i386”.

How to ssh into lxc as root:

1:lxc-attach -n my-container
2:to apt-get install ssh
3:vim /etc/ssh/sshd_config
4:Go to line 28: "PermitRootLogin" Change it to yes
5:Then you're allow to ssh into root
6:Remember to set a password before logging out
7./etc/init.d/ssh restart

8:After logging out there is one more thing you have to do, you have to assign IP to that lxc
  in order to ssh into that lxc.
9:At your host , vim /var/lib/my-container/config
10:Add
lxc.network.ipv4 = 10.0.3.4 (According to gateway IP)
lxc.network.ipv4.gateway = 10.0.3.1

11.(Optional) when you use lxc-ls -f you will see your container is having two ip , one is the one you set and one is the dhcp ip , you can remove it by edit /etc/network/interfaces in your container, remove the line below auto eth0 


To Set lxc’s core and Ram
put below code in /var/lib/lxc/container-name/config

lxc.cgroup.cpuset.cpus = 0,1
lxc.cgroup.memory.soft_limit_in_bytes = 268435456
lxc.cgroup.memory.limit_in_bytes = 1073741824

Host Network subnet information is at /etc/default/lxc-net . For more information about making subnet or set your own range of ip’s , https://wiki.debian.org/LXC/SimpleBridge

Back To Top