Professional Documents
Culture Documents
How To Create and Launch LXC Linux Containers With LXC Commands
How To Create and Launch LXC Linux Containers With LXC Commands
com/2016/01/create-lxc-containers/
≡ MENU
Like 0 Tweet
LXC Containers are a very quick way to create a psuedo virtual environment.
In the previous LXC article, we explained how to install and configure LXC linux
containers.
In this tutorial, we’ll explain how to create a new Linux container, start the
container, and login to the LXC virtual console to use the new container.
1 of 23 6/13/21, 12:51
How to Create and Launch LXC Linux Containers with LXC Commands https://www.thegeekstuff.com/2016/01/create-lxc-containers/
CentOS
Ubuntu
Fedora
OpenSUSE
Gentoo
Debian
Oracle Linux
ArchLinux
# ls -1 /usr/local/share/lxc/templates
lxc-alpine
lxc-altlinux
lxc-archlinux
lxc-busybox
lxc-centos
lxc-cirros
lxc-debian
lxc-download
2 of 23 6/13/21, 12:51
How to Create and Launch LXC Linux Containers with LXC Commands https://www.thegeekstuff.com/2016/01/create-lxc-containers/
lxc-fedora
lxc-gentoo
lxc-openmandriva
lxc-opensuse
lxc-oracle
lxc-plamo
lxc-sshd
lxc-ubuntu
lxc-ubuntu-cloud
In this example, this will create the CentOS container with centos minimal install.
This will download all the packages that are required to run the CentOS minimal
(for example, approximately around 140 packages), and install them as part of the
MyCentOSContainer1 container
3 of 23 6/13/21, 12:51
How to Create and Launch LXC Linux Containers with LXC Commands https://www.thegeekstuff.com/2016/01/create-lxc-containers/
/usr/local/share/lxc/templates/lxc-centos
...
...
...
...
Download complete.
4 of 23 6/13/21, 12:51
How to Create and Launch LXC Linux Containers with LXC Commands https://www.thegeekstuff.com/2016/01/create-lxc-containers/
So, in the above example, for the LXC container that we just created, temporary
root password is under the following:
# cat /usr/local/var/lib/lxc/MyCentOSContainer1/tmp_root_pass
Root-MyCentOSContainer1-pf7qMB
You can change the root password of your container at any time, even if your
container is turned off by using chroot from the control host as shown below.
New password:
# lxc-start -n MyCentOSContainer1
5 of 23 6/13/21, 12:51
How to Create and Launch LXC Linux Containers with LXC Commands https://www.thegeekstuff.com/2016/01/create-lxc-containers/
MyCentOSContainer1 login: init: rcS main process (8) killed by TERM signal
Mounting filesystems: [ OK ]
Starting sshd: [ OK ]
MyCentOSContainer1 login:
If you get the following “container failed to start” error message, then something is
wrong in your configuration.
# lxc-start -n MyCentOSContainer1
lxc-start: lxc_start.c: main: 346 To get more details, run the container in foreground mod
lxc-start: lxc_start.c: main: 348 Additional information can be obtained by setting the --
To find-out exactly what is wrong with your configuration, run the LXC container
6 of 23 6/13/21, 12:51
How to Create and Launch LXC Linux Containers with LXC Commands https://www.thegeekstuff.com/2016/01/create-lxc-containers/
If you get the following, “failed to attach to bridge”, “failed to create netdev”,
“failed to create the network” error message, then bridge adapter is not configured
properly on your system.
Check the ifcfg-br0 settings that we mentioned in our earlier LXC Linux Container
setup article, to make sure you have the bridge configuration setup properly and
working.
# lxc-start -F -n MyCentOSContainer1
lxc-start: conf.c: instantiate_veth: 2796 failed to attach 'veth8VPW29' to the bridge 'lxc
lxc-start: lxc_start.c: main: 348 Additional information can be obtained by setting the --
# lxc-info -n MyCentOSContainer1
Name: MyCentOSContainer1
State: RUNNING
7 of 23 6/13/21, 12:51
How to Create and Launch LXC Linux Containers with LXC Commands https://www.thegeekstuff.com/2016/01/create-lxc-containers/
PID: 7696
IP: 192.168.100.101
Link: vethLNI1UH
# lxc-stop -n MyCentOSContainer1
Cloning the container can be done using lxc-clone command as shown below. In
this case, the new container name is MyCentOSContainer2
8 of 23 6/13/21, 12:51
How to Create and Launch LXC Linux Containers with LXC Commands https://www.thegeekstuff.com/2016/01/create-lxc-containers/
# lxc-destroy -n MyCentOSContainer2
# lxc-console -n MyCentOSContainer1
Connected to tty 1
Type Ctrl+a q to exit the console, Ctrl+a Ctrl+a to enter Ctrl+a itself
MyCentOSContainer1 login:
9 of 23 6/13/21, 12:51
How to Create and Launch LXC Linux Containers with LXC Commands https://www.thegeekstuff.com/2016/01/create-lxc-containers/
First, use lxc-config -l option, which will just display all the available
configurations as shown below.
# lxc-config -l
lxc.default_config
lxc.lxcpath
lxc.bdev.lvm.vg
lxc.bdev.lvm.thin_pool
lxc.bdev.zfs.root
lxc.cgroup.use
lxc.cgroup.pattern
# lxc-config lxc.default_config
/usr/local/etc/lxc/default.conf
# cat /usr/local/etc/lxc/default.conf
lxc.network.type = veth
lxc.network.link = virbr0
lxc.network.flags = up
10 of 23 6/13/21, 12:51
How to Create and Launch LXC Linux Containers with LXC Commands https://www.thegeekstuff.com/2016/01/create-lxc-containers/
The following command will display the LXC patch where all the containers are
stored.
# lxc-config lxc.lxcpath
/usr/local/var/lib/lxc
As we see below, we see the two containers that we created under this directory.
# cd /usr/local/var/lib/lxc
# ls
MyCentOSContainer1 MyCentOSContainer2
Under the container directory, you’ll see the config file, which contains all the
basic configuration information for that particular container as shown below.
# cd /usr/local/var/lib/lxc/MyCentOSContainer1
# vi config
lxc.network.type = veth
lxc.network.link = virbr0
lxc.network.hwaddr = fb:bb:f2:87:e8:17
lxc.network.flags = up
lxc.rootfs = /usr/local/var/lib/lxc/MyCentOSContainer1/rootfs
lxc.include = /usr/local/share/lxc/config/centos.common.conf
11 of 23 6/13/21, 12:51
How to Create and Launch LXC Linux Containers with LXC Commands https://www.thegeekstuff.com/2016/01/create-lxc-containers/
lxc.arch = x86_64
lxc.utsname = MyCentOSContainer1
12 of 23 6/13/21, 12:51
How to Create and Launch LXC Linux Containers with LXC Commands https://www.thegeekstuff.com/2016/01/create-lxc-containers/
Tagged as: Chroot LXC Container, lxc-clone Command Examples, lxc-config Command Examples, lxc-console Command Examples,
lxc-create Command Examples, lxc-destroy Command Examples, lxc-info Command Examples, lxc-start Command Examples, lxc-
Thanks ..I searched the right document for lxc and found one.. Keep
posting more in containers ..good work of you continues ..
LINK
Ramesh,
I set this up on Arch Linux and was trying to login using the ‘lxc-console -n
MyCentOSContainer1’ command. I tried logging in using both ‘root’ and ‘admin’ to
login without success. I’m stuck on this step. Please help.
Scott
13 of 23 6/13/21, 12:51
How to Create and Launch LXC Linux Containers with LXC Commands https://www.thegeekstuff.com/2016/01/create-lxc-containers/
LINK
LINK
LINK
LINK
14 of 23 6/13/21, 12:51
How to Create and Launch LXC Linux Containers with LXC Commands https://www.thegeekstuff.com/2016/01/create-lxc-containers/
Hi Ramesh,
lxc-start -n MyCentOSContainer1
15 of 23 6/13/21, 12:51
How to Create and Launch LXC Linux Containers with LXC Commands https://www.thegeekstuff.com/2016/01/create-lxc-containers/
LINK
Hi Jesus/Ramesh,
I am getting same error , are you able to solve this problem if yes then please help
me out. I am new to linux.
lxc-start: cgfs.c: handle_cgroup_settings: 2091 Device or resource busy – failed to
set memory.use_hierarchy to 1; continuing
lxc-start: cgfs.c: handle_cgroup_settings: 2091 Device or resource busy – failed to
set memory.use_hierarchy to 1; continuing
lxc-start: utils.c: open_without_symlink: 1626 No such file or directory – Error
examining fuse in /usr/local/lib/lxc/rootfs/sys/fs/fuse/connections
lxc-start: utils.c: open_without_symlink: 1626 No such file or directory – Error
examining cgroup in /usr/local/lib/lxc/rootfs/sys/fs/cgroup
lxc-start: cgfs.c: cgroupfs_mount_cgroup: 1372 No such file or directory – could
not mount tmpfs to /sys/fs/cgroup in the container
lxc-start: conf.c: lxc_mount_auto_mounts: 866 No such file or directory – error
mounting /sys/fs/cgroup
lxc-start: conf.c: lxc_setup: 3936 failed to setup the automatic mounts for
‘dmszone’
lxc-start: start.c: do_start: 717 failed to setup the container
lxc-start: sync.c: __sync_wait: 51 invalid sequence number 1. expected 2
lxc-start: start.c: __lxc_start: 1192 failed to spawn ‘dmszone’
lxc-start: lxc_start.c: main: 344 The container failed to start.
lxc-start: lxc_start.c: main: 348 Additional information can be obtained by setting
the –logfile and –logpriority options.
16 of 23 6/13/21, 12:51
How to Create and Launch LXC Linux Containers with LXC Commands https://www.thegeekstuff.com/2016/01/create-lxc-containers/
LINK
Hi,
I am also getting the below error. Any help will be highly appreciated.
17 of 23 6/13/21, 12:51
How to Create and Launch LXC Linux Containers with LXC Commands https://www.thegeekstuff.com/2016/01/create-lxc-containers/
LINK
Leave a Comment
Name
Website
Comment
Save my name, email, and website in this browser for the next time I comment.
Submit
18 of 23 6/13/21, 12:51
How to Create and Launch LXC Linux Containers with LXC Commands https://www.thegeekstuff.com/2016/01/create-lxc-containers/
Search
Download
EBOOKS
19 of 23 6/13/21, 12:51
How to Create and Launch LXC Linux Containers with LXC Commands https://www.thegeekstuff.com/2016/01/create-lxc-containers/
Linux 101 Hacks 2nd Edition eBook - Practical Examples to Build a Strong Foundation in Linux
Bash 101 Hacks eBook - Take Control of Your Bash Command Line and Shell Scripting
Sed and Awk 101 Hacks eBook - Enhance Your UNIX / Linux Life with Sed and Awk
Vim 101 Hacks eBook - Practical Examples for Becoming Fast and Productive in Vim Editor
POPULAR POSTS
15 Essential Accessories for Your Nikon or Canon DSLR Camera
12 Amazing and Essential Linux Books To Enrich Your Brain and Library
20 of 23 6/13/21, 12:51
How to Create and Launch LXC Linux Containers with LXC Commands https://www.thegeekstuff.com/2016/01/create-lxc-containers/
3 Steps to Perform SSH Login Without Password Using ssh-keygen & ssh-copy-id
21 of 23 6/13/21, 12:51
How to Create and Launch LXC Linux Containers with LXC Commands https://www.thegeekstuff.com/2016/01/create-lxc-containers/
CATEGORIES
Linux Tutorials
Vim Editor
Sed Scripting
Awk Scripting
Nagios Monitoring
OpenSSH
IPTables Firewall
MySQL Database
Perl Programming
Google Tutorials
Ubuntu Tutorials
PostgreSQL DB
C Programming
C++ Programming
Oracle Database
VMware Tutorials
22 of 23 6/13/21, 12:51
How to Create and Launch LXC Linux Containers with LXC Commands https://www.thegeekstuff.com/2016/01/create-lxc-containers/
23 of 23 6/13/21, 12:51