LXC(Linux Containers) is a user-space interface for the Linux kernel container features. Through a powerful API and simple tools, it lets Linux users easily create and manage system or application containers. I tried to consolidate most of the daily usages who ever is working on the lxc in simple form.
Installation:
Centos: yum install lxc lxc-templates
Ubuntu: sudo apt-get install lxc lxc-templates
Installation:
Centos: yum install lxc lxc-templates
Ubuntu: sudo apt-get install lxc lxc-templates
Additional information:
LXD is a container "hypervisor" founded and currently led by canonical and ubuntu with contributions from a range of other companies and individual contributors.
Some of the biggest features of LXD are :
1. Secure by design(resource restrictions ..etc )
2. Scalable ( from containers on laptop to many compute nodes..)
3. Live migration
4. Image based ... etc
LXD uses LXC through liblxc and its go binding to create and manage containers. we could consider that to be an alternative to LXC's tools and distribution to template systems with added features that coming from being controllable over the network.
LXD Reference : https://linuxcontainers.org/lxd/articles/
LXC Command Manual:
lxc-commands | Descriptions | Commands | Descriptions |
lxc-checkconfig | check the current kernel for lxc support | ||
lxc-create | creates a container, -t template shortname of an existing lxc-template script called by lxc-create. e.g ls /usr/share/lxc/templates | lxc-create -t centos -n first | create a "first" container using "centos" template |
lxc-start | run an application inside a container | lxc-start -n first | start container "first" in background |
lxc-console | Launch a console for the specified container (ctrl-a + q to detach) | lxc-console -n first | enter container in one of the way i.e using console |
lxc-attach | run the specified command inside container(bypassing console login) Kernel version >=3.8 | lxc-attach -n first lxc-attach -n first -- /etc/init.d/sshd restart | spawn bash directly in the container and restart openssh Running inside the container |
lxc-config | query LXC system configuration | lxc-config -l first | lets you know all the valid keys on the container |
lxc-info | queries and shows information about containers | lxc-info -n first | Display information of first container, once you have the IP you can SSH to container |
lxc-stop | By default, it will request clean shutdown(SIGPWR) of the container to container's init process waiting for 60 sec for exit and then returning. If it fails(SIGKILL) to force shutdown | lxc-stop -n first lxc-stop -n first -k | stop container cleanly from outside incase it fails provide "-k" |
lxc-autostart | containers with lxc.start.auto = 1 to start at boot time. To edit each container has /var/lib/lxc/<container>/config edit over there. You can use Lxc-autostart to start/stop/reboot/kill when lxc.start.auto = 1 lxc.group = centos belongs to centos group | lxc-autostart -r -g centos | restart containers belongs to group of centos |
lxc-ls | list the containers existing on the system | lxc-ls -f | list all containers per line with its name,state,ipv4,ipv6 address |
lxc-freeze | freeze all process inside containers, useful for batch managers to Schdule a group of processes | lxc-freeze -n first | process inside first container frozen, to view state lxc-ls -f |
lxc-unfreeze | thaw all process previously frozen containers | lxc-unfreeze -n first | process resumed in first container, view staus lxc-ls -f |
lxc-device | manage devices of running containers | lxc-device [add/del] -n first /dev/ttyS0 | creates/deletes /dev/ttyS0 in container first based on matching device on the host |
lxc-copy | lxc-clone and lxc-start-ephemeral has been depreciated and lxc-copy has Been replaced. Creates and optionally starts copies of existing containers Whole root fs copied to new container | lxc-copy -n first -N clone-first | Create a clone of first container |
lxc-snapshot | snapshot existing container, i.e small copy-on-write copies of the original container. | lxc-snapshot -n first -c snap-first lxc-snapshot -n first -L -C Lxc-snapshot -n first -r snap-first lxc-snapshot -n first -r snap0 firstsnap0 | capture the snapshot confirm your snapshot created revert container at a later point of time if you wish restore snapshot as its own container |
lxc-top | displays container statistics.for performance reasons kernel does not account kernel memory unless kernel memory set | ||
lxc-destroy | destroys the system object previously created by the lxc-create command. Stop container before destroying | lxc-destroy -n first | Destroy first container |
LXC Reference :
Thanks for re-sharing !
No comments:
Post a Comment