How to Install and Configure LXC Container on Ubuntu 16.04

  1. Lightweight and resource friendly.
  2. Rapid and easy deployment.
  3. Run multiple versions of an operating system on a single server.
  4. Comprehensive process and resource isolation.

Requirements

  1. A fresh Alibaba Cloud Ubuntu 16.04 instance with minimum 2GB of RAM.
  2. A static IP address is configured.
  3. A Root password is set up on the server.

Launch Alibaba Cloud ECS Instance

apt-get update -y

Install LXC

apt-get install lxc lxc-templates -y
lxc-checkconfig
Kernel configuration not found at /proc/config.gz; searching...
Kernel configuration found at /boot/config-4.2.0-27-generic
--- Namespaces ---
Namespaces: enabled
Utsname namespace: enabled
Ipc namespace: enabled
Pid namespace: enabled
User namespace: enabled
Network namespace: enabled
Multiple /dev/pts instances: enabled
--- Control groups ---
Cgroup: enabled
Cgroup clone_children flag: enabled
Cgroup device: enabled
Cgroup sched: enabled
Cgroup cpu account: enabled
Cgroup memory controller: enabled
Cgroup cpuset: enabled
--- Misc ---
Veth pair device: enabled
Macvlan: enabled
Vlan: enabled
Bridges: enabled
Advanced netfilter: enabled
CONFIG_NF_NAT_IPV4: enabled
CONFIG_NF_NAT_IPV6: enabled
CONFIG_IP_NF_TARGET_MASQUERADE: enabled
CONFIG_IP6_NF_TARGET_MASQUERADE: enabled
CONFIG_NETFILTER_XT_TARGET_CHECKSUM: enabled
FUSE (for use with lxcfs): enabled
--- Checkpoint/Restore ---
checkpoint restore: enabled
CONFIG_FHANDLE: enabled
CONFIG_EVENTFD: enabled
CONFIG_EPOLL: enabled
CONFIG_UNIX_DIAG: enabled
CONFIG_INET_DIAG: enabled
CONFIG_PACKET_DIAG: enabled
CONFIG_NETLINK_DIAG: enabled
File capabilities: enabled
Note : Before booting a new kernel, you can check its configuration
usage : CONFIG=/path/to/config /usr/bin/lxc-checkconfig

Create LXC Container

ls /usr/share/lxc/templates/
lxc-alpine    lxc-archlinux  lxc-centos  lxc-debian    lxc-fedora  lxc-openmandriva  lxc-oracle  lxc-slackware   lxc-sshd    lxc-ubuntu-cloud
lxc-altlinux lxc-busybox lxc-cirros lxc-download lxc-gentoo lxc-opensuse lxc-plamo lxc-sparclinux lxc-ubuntu
lxc-create -n new-container -t ubuntu
Download complete
Copy /var/cache/lxc/xenial/rootfs-amd64 to /var/lib/lxc/new-container/rootfs ...
Copying rootfs to /var/lib/lxc/new-container/rootfs ...
Generating locales (this might take a while)...
en_IN.UTF-8... done
Generation complete.
Creating SSH2 RSA key; this may take some time ...
2048 SHA256:kiRG9aMIT87ZRJ/+RJoKh9dO7ykS0MNQmNKlbgDveiM root@mail.distcourt.local (RSA)
Creating SSH2 DSA key; this may take some time ...
1024 SHA256:Y0Ajo4RuUP3ty+BJOmHrQPscF+9oxDSfgLTALBE3/Yg root@mail.distcourt.local (DSA)
Creating SSH2 ECDSA key; this may take some time ...
256 SHA256:TsHzuCEgoRAMobpdUJCVCyRQo2YgKpGEZLZp4OF1iBw root@mail.distcourt.local (ECDSA)
Creating SSH2 ED25519 key; this may take some time ...
256 SHA256:wehDNjEy/AxVknDWj7BFTtvGKUnVXKLcmTTbm63OyM0 root@mail.distcourt.local (ED25519)
invoke-rc.d: could not determine current runlevel
invoke-rc.d: policy-rc.d denied execution of start.
Current default time zone: 'Etc/UTC'
Local time is now: Mon Jul 30 07:40:47 UTC 2018.
Universal Time is now: Mon Jul 30 07:40:47 UTC 2018.
##
# The default user is 'ubuntu' with password 'ubuntu'!
# Use the 'sudo' command to run tasks as root in the container.
##
lxc-ls
new-container

Start Container

lxc-start -n new-container -d
lxc-console -n new-container
Connected to tty 1
Type <Ctrl+a q> to exit the console, <Ctrl+a Ctrl+a> to enter Ctrl+a itself
Ubuntu 16.04.5 LTS new-container pts/0new-container login: ubuntu
Password:
Welcome to Ubuntu 16.04.5 LTS (GNU/Linux 4.4.0-45-generic x86_64)
* Documentation: https://help.ubuntu.com
* Management: https://landscape.canonical.com
* Support: https://ubuntu.com/advantage
The programs included with the Ubuntu system are free software;
the exact distribution terms for each program are described in the
individual files in /usr/share/doc/*/copyright.
Ubuntu comes with ABSOLUTELY NO WARRANTY, to the extent permitted by
applicable law.
To run a command as administrator (user "root"), use "sudo <command>".
See "man sudo_root" for details.
ubuntu@new-container:~$

Working with LXC Container

lxc-info -n new-container
Name:           new-container
State: RUNNING
PID: 26342
IP: 10.0.3.66
CPU use: 0.20 seconds
BlkIO use: 8.00 KiB
Memory use: 13.44 MiB
KMem use: 0 bytes
Link: veth9DB525
TX bytes: 1.34 KiB
RX bytes: 2.09 KiB
Total bytes: 3.43 KiB
lxc-start -n new-container
lxc-stop -n new-container
lxc-freeze -n new-container
lxc-unfreeze -n new-container
lxc-stop -n new-container
lxc-snapshot -n new-container
lxc-snapshot: lxccontainer.c: do_lxcapi_snapshot: 3405 Snapshot of directory-backed container requested.
lxc-snapshot: lxccontainer.c: do_lxcapi_snapshot: 3406 Making a copy-clone. If you do want snapshots, then
lxc-snapshot: lxccontainer.c: do_lxcapi_snapshot: 3407 please create an aufs or overlayfs clone first, snapshot that
lxc-snapshot: lxccontainer.c: do_lxcapi_snapshot: 3408 and keep the original container pristine.
lxc-snapshot -L -n new-container
snap0 (/var/lib/lxc/new-container/snaps) 2018:07:30 13:43:16
lxc-snapshot -r snap0 -n new-container
lxc-stop -n new-container
lxc-destroy -n new-container

Install LXC Web Panel

wget https://lxc-webpanel.github.io/tools/install.sh -O - | bash
Installing requirement...
+ Installing Python pip
Extracting templates from packages: 100%
| + Flask Python...
Collecting flask==0.9
Downloading https://files.pythonhosted.org/packages/49/0a/fe5021b35436202d3d4225a766f3bdc7fb51521ad89e73c5162db36cdbc7/Flask-0.9.tar.gz (481kB)
100% |################################| 491kB 598kB/s
Collecting Werkzeug>=0.7 (from flask==0.9)
Downloading https://files.pythonhosted.org/packages/20/c4/12e3e56473e52375aa29c4764e70d1b8f3efa6682bef8d0aae04fe335243/Werkzeug-0.14.1-py2.py3-none-any.whl (322kB)
100% |################################| 327kB 517kB/s
Collecting Jinja2>=2.4 (from flask==0.9)
Downloading https://files.pythonhosted.org/packages/7f/ff/ae64bacdfc95f27a016a7bed8e8686763ba4d277a78ca76f32659220a731/Jinja2-2.10-py2.py3-none-any.whl (126kB)
100% |################################| 133kB 544kB/s
Collecting MarkupSafe>=0.23 (from Jinja2>=2.4->flask==0.9)
Downloading https://files.pythonhosted.org/packages/4d/de/32d741db316d8fdb7680822dd37001ef7a448255de9699ab4bfcbdf4172b/MarkupSafe-1.0.tar.gz
Building wheels for collected packages: flask, MarkupSafe
Running setup.py bdist_wheel for flask ... done
Stored in directory: /root/.cache/pip/wheels/69/1b/77/d1aa13cdcc09430d1ba010a48e2cb59fda00f4ef18620ca8dc
Running setup.py bdist_wheel for MarkupSafe ... done
Stored in directory: /root/.cache/pip/wheels/33/56/20/ebe49a5c612fffe1c5a632146b16596f9e64676768661e4e46
Successfully built flask MarkupSafe
Installing collected packages: Werkzeug, MarkupSafe, Jinja2, flask
Successfully installed Jinja2-2.10 MarkupSafe-1.0 Werkzeug-0.14.1 flask-0.9
+ Installing Git
Cloning LXC Web Panel...
Cloning into '/srv/lwp'...
remote: Counting objects: 243, done.
remote: Total 243 (delta 0), reused 0 (delta 0), pack-reused 243
Receiving objects: 100% (243/243), 198.33 KiB | 141.00 KiB/s, done.
Resolving deltas: 100% (108/108), done.
Checking connectivity... done.
Installation complete!
Adding /etc/init.d/lwp...
Done
Starting server...done.
Connect you on http://your-ip-address:5000/
wget https://lxc-webpanel.github.io/tools/update.sh -O - | bash

Related Alibaba Cloud Products

--

--

--

Follow me to keep abreast with the latest technology news, industry insights, and developer trends. Alibaba Cloud website:https://www.alibabacloud.com

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Coding Standards in Java

Selectable Card List in Flutter w/ Delete and Archive actions — Part 1

How write operation is executed in Hadoop Distributed File System??

Automatic certificate management

Pros and Cons of IT Infrastructure Management Services

Gembo Next Gen Cloud Rendering

Unit testing a Dart server

Installation Minikube — Windows 10

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Alibaba Cloud

Alibaba Cloud

Follow me to keep abreast with the latest technology news, industry insights, and developer trends. Alibaba Cloud website:https://www.alibabacloud.com

More from Medium

Standalone within Docker container

S3 Server Side Logging query — Part 1 of N

Raspberry-Pi: A web server with CI/CD pipeline (Part-2)

Docker image

Setup Apache Hadoop on local Ubuntu System