Demonstration on LXC containers
Resources
This demonstration directly uses a subpart of the content of the online try of LXC/LXD at this link. Please go to the corresponding link and start the online try.
Creating a LXC container
-
lxc image list
No images are currently available on the host OS. -
lxc launch images:ubuntu/18.04 first
This command starts a container called “first” using the Ubuntu 18.04 image. -
lxc list
Your new container is listed in the list of containers. -
lxc image list
The ubuntu/18.04 is now listed in the list of known images. -
lxc info first
Get some info on your container.
Launch a command on the container
-
lxc exec first -- apt-get update
andlxc exec first -- apt-get install sl -y
These commands respectively execute the commandapt-get update
andapt-get install sl -y
in your container. The packagesl
is a well known ASCII train application on Linux. Let’s try it! -
lxc exec first -- /usr/games/sl
Did you see the train?
Get a bash on the container
-
lxc exec first -- bash
Now you should seeroot@first:~#
. This means that you’re having a bash directly on your container! -
mkdir test
andtouch test/toto.org
andls test/
You’ve just created a directorytest
and aorg
file in ittoto.org
. If you don’t know emacs-org mode, take a look! It could be helpful to handle your thesis project in a light way! (bibliography management, daily TODO lists, agenda, reproducible research and much more!)
Stop the container and restart it
-
exit
You’ve quit the bash on your container. -
lxc stop first
You’ve stopped your container. -
lxc start first
You’ve started it again. -
lxc exec first -- /usr/games/sl
andlxc exec first -- ls test/
You’ve checked that your new packagesl
and your new file are still there!
Snapshot of the container and restoration
-
lxc snapshot first clean
You’ve just created a snapshot from your running container first under the nameclean
. -
lxc exec first -- rm -Rf /etc /usr
Oups! You’ve just deleted a very important part of the Linux OS! -
lxc exec first -- bash
Ohhh no! Your bash is broken! -
exit
-
lxc restore first clean
Ok it seems to work to restore thefirst
container! -
lxc exec first -- bash
andls test/
YES!