[lxc-users] Howto/Tutorial wanted: Running an application inside a container

Serge Hallyn serge.hallyn at ubuntu.com
Sat May 10 22:54:34 UTC 2014


Quoting Johannes Kastl (mail at ojkastl.de):
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
> 
> Hi everyone,
> 
> I thought running a single application inside a container was one of
> the main advantages of lxc over 'full'virtualization like KVM. But it
> seems I fail to find a nice tutorial how to do this. Any hints?
> 
> I found some sites, but the pages I found were pretty old (2012?
> 2011?), so I am not sure if they are still valid.
> 
> I got this far with running apache inside the container:
> Create a rootfs containing empty directories for proc, sys, ...
> Copy over apache's config into the rootfs
> Create a config file that says:
> 
> > lxc.network.type = veth lxc.network.flags = up lxc.network.link =
> > virbr0 lxc.network.hwaddr = 02:00:e4:28:dd:77 lxc.network.name =
> > eth0 lxc.rootfs = /some/path/to/Apache_Test4 lxc.utsname =
> > Apache_Test4
> 
> I can then run
> lxc-execute -n Apache_Test4 -f /path/to/the/config -- /usr/sbin/httpd2
> 
> And I get:
> > lxc-execute: Failed to find an lxc-init lxc-execute: invalid
> > sequence number 1. expected 4 lxc-execute: failed to spawn
> > 'Apache_Test4' lxc-execute: Device or resource busy - cgroup_rmdir:
> > failed to delete /sys/fs/cgroup/hugetlb/lxc/Apache_Test4 
> > lxc-execute: Device or resource busy - cgroup_rmdir: failed to
> > delete /sys/fs/cgroup/perf_event/lxc/Apache_Test4 lxc-execute:
> > Device or resource busy - cgroup_rmdir: failed to delete
> > /sys/fs/cgroup/blkio/lxc/Apache_Test4 lxc-execute: Device or
> > resource busy - cgroup_rmdir: failed to delete
> > /sys/fs/cgroup/net_cls/lxc/Apache_Test4 lxc-execute: Device or
> > resource busy - cgroup_rmdir: failed to delete
> > /sys/fs/cgroup/freezer/lxc/Apache_Test4 lxc-execute: Device or
> > resource busy - cgroup_rmdir: failed to delete
> > /sys/fs/cgroup/devices/lxc/Apache_Test4 lxc-execute: Device or
> > resource busy - cgroup_rmdir: failed to delete
> > /sys/fs/cgroup/memory/lxc/Apache_Test4 lxc-execute: Device or
> > resource busy - cgroup_rmdir: failed to delete
> > /sys/fs/cgroup/cpu,cpuacct/lxc/Apache_Test4 lxc-execute: Device or
> > resource busy - cgroup_rmdir: failed to delete
> > /sys/fs/cgroup/cpuset/lxc/Apache_Test4
> 
> And all the links I found for the "failed ...lxc-init" point me to
> installing lxc inside the container. Which is not possible, as it is
> no 'complete' OS inside. I also failed to find a file called lxc-init
> on my openSUSE host where I installed lxc 1.0.3.

I'm not sure why you're not finding it, but you can just

	git clone git://github.com/lxc/lxc
	cd lxc
	sh autogen.sh
	./configure --prefix=/usr
	make -j4
	sudo cp src/lxc/init.lxc /usr/sbin/

Now I'm not sure what lxc version you're on, but you should be safe if
you just copy /usr/sbin/init.lxc to /sbin/lxc-init and
/usr/lib/lxc/lxc-init.  Check the libraries it linked again (ldd
/usr/sbin/init.lxc) and make sure all the directories will be
bind-mounted from the host into the container.

If it still says it fails to find lxc-init, it could be because of
a missing library, but also try

	lxc-start -n container -l trace -o outfile

and look through outfile to see which filenames lxc tried to execute
lxc-init as, then copy init.lxc there.


More information about the lxc-users mailing list