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 listNo images are currently available on the host OS. -
lxc launch images:ubuntu/18.04 firstThis command starts a container called “first” using the Ubuntu 18.04 image. -
lxc listYour new container is listed in the list of containers. -
lxc image listThe ubuntu/18.04 is now listed in the list of known images. -
lxc info firstGet some info on your container.
Launch a command on the container
-
lxc exec first -- apt-get updateandlxc exec first -- apt-get install sl -yThese commands respectively execute the commandapt-get updateandapt-get install sl -yin your container. The packageslis a well known ASCII train application on Linux. Let’s try it! -
lxc exec first -- /usr/games/slDid you see the train?
Get a bash on the container
-
lxc exec first -- bashNow you should seeroot@first:~#. This means that you’re having a bash directly on your container! -
mkdir testandtouch test/toto.organdls test/You’ve just created a directorytestand aorgfile 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
-
exitYou’ve quit the bash on your container. -
lxc stop firstYou’ve stopped your container. -
lxc start firstYou’ve started it again. -
lxc exec first -- /usr/games/slandlxc exec first -- ls test/You’ve checked that your new packagesland your new file are still there!
Snapshot of the container and restoration
-
lxc snapshot first cleanYou’ve just created a snapshot from your running container first under the nameclean. -
lxc exec first -- rm -Rf /etc /usrOups! You’ve just deleted a very important part of the Linux OS! -
lxc exec first -- bashOhhh no! Your bash is broken! -
exit -
lxc restore first cleanOk it seems to work to restore thefirstcontainer! -
lxc exec first -- bashandls test/YES!