install lxc
* sudo for all lxc command
lxc-create -t ubuntu -n project-name
## The OS installed here is very limited, only pure rootfs, so most of commands and packages need to be installed manually. And the default user and password is ubuntu.ubuntu##
configuration files
--------------------
/var/lib/lxc/project-name/config
- add mount socket config into it
#lxc.mount.entry = /dev/dri dev/dri none bind,optional,create=dir
#lxc.mount.entry = /dev/snd dev/snd none bind,optional,create=dir1
# For mount the X socket and use it
lxc.mount.entry = /tmp/.X11-unix tmp/.X11-unix none bind,optional,create=dir
lxc.mount.entry = /dev/video0 dev/video0 none bind,optional,create=file
---------------------
Run LXC under default unity7 with X socket
lxc-start -n project-name
install bash-completion
(for tab usage, and need to reboot for enable)
install firefox
$firefox --display=:0
(Or you can do "export DISPLAY=:0)
Now you can see the firefox running on the screen via LXC
Run LXC under default unity7 with MIR socket
install mir-demos
switch to console mode (tty1)
sudo mir-demo-server-shell (will create the mir on tty1)
switch to tty2
change the default socket config, /var/lib/lxc/project-name/config, to
lxc.mount.entry = /tmp/mir tmp/mir none bind,optional,create=dir
create /tmp/mir and MOVE mir_socket from /tmp to /tmp/mir
chmod 777 /tmp/mir/mir_socket
### in container ###
lxc-start -n project-name
install mir-demos
* check /tmp/mir to see if there is a "mir_socket" file.
mir_demo_client_eglplasma -m /tmp/mir/mir_socket
DONE!!!
Unprivileged LXC containers
add below 2 lines in config file
lxc.id_map = u 0 100000 65536
lxc.id_map = g 0 100000 65536
Then, assign yourself a set of uids and gids with:
sudo usermod –add-subuids 100000-165536 $USER
sudo usermod –add-subgids 100000-165536 $USER
sudo chmod +x $HOME
Now create ~/.config/lxc/default.conf with the following content:
lxc.network.type = veth
lxc.network.link = lxcbr0
lxc.network.flags = up
lxc.network.hwaddr = 00:16:3e:xx:xx:xx
lxc.id_map = u 0 100000 65536
lxc.id_map = g 0 100000 65536
And /etc/lxc/lxc-usernet with:
veth lxcbr0 10
And that’s all you need. Now let’s create our first unprivileged container with:
lxc-create -t download -n p1 -- -d ubuntu -r trusty -a amd64
mir_demo_client_eglplasma -m /tmp/mir/mir_socket
DONE!!!
Unprivileged LXC containers
add below 2 lines in config file
lxc.id_map = u 0 100000 65536
lxc.id_map = g 0 100000 65536
Then, assign yourself a set of uids and gids with:
sudo usermod –add-subuids 100000-165536 $USER
sudo usermod –add-subgids 100000-165536 $USER
sudo chmod +x $HOME
Now create ~/.config/lxc/default.conf with the following content:
lxc.network.type = veth
lxc.network.link = lxcbr0
lxc.network.flags = up
lxc.network.hwaddr = 00:16:3e:xx:xx:xx
lxc.id_map = u 0 100000 65536
lxc.id_map = g 0 100000 65536
And /etc/lxc/lxc-usernet with:
And that’s all you need. Now let’s create our first unprivileged container with:
lxc-create -t download -n p1 -- -d ubuntu -r trusty -a amd64
chmod +x for /home/user/.local and /home/user/.local/share
the config file will store at $HOME/.local/share/lxc/project-name/config
DONE!!!
reference site
https://www.stgraber.org/2013/12/20/lxc-1-0-your-first-ubuntu-container/
沒有留言:
張貼留言