There is an other way I use to create virtual machines, a much more sophisticated way, a fun way. It is a way even the Jedi would find civilized, although zero lightsaber dance is involved, so I am not entirely sure. One thing is sure, this way is at least as colorful as those lightsabers in the Star Wars saga.
So there are two things that you will have to install. The first is the ClusterControl software. There is a howto here you can follow. You will also need to install the s9s command line client for the ClusterControl controller as described here. There is also a web UI for the ClusterControl that is a great resource for many people, but I am a command line kind of guy so we are going to play with that.
If you followed the previous post Using LXC Containers for Testing you can simply register your server on the controller to actually start using it from the command line. It is very simple, you already set up the server, the ClusterControl has a passwordless SSH and sudo to the container server, it can login and do the work for you. Here is how registering a server looks like:
The screenshot shows the --register with the server's url. Here the lxc:// part just tells the controller that you want it to go there and run those lxc-* commands for you, to consider the server an LXC container server. The screenshot also shows the --stat option that is used to find the details about the given server after it is registered. Fortunately the lshw package is installed on the server, so the controller could use it to find a number of details about the hardware. This is sweet, it helps to actually know what's what, right? This beauty has 8 CPUs, Quad-Core AMD Opteron(tm) Processor 8384, so 32 cores... well, it seems this beauty reached a ripe old age of tensomething years, that is a serious time for a compute node, but still, she has some moves, she can hold her liquor.
Aaanyhow, the server is not alone, I also registered two other servers the same way, so when I list some of the resources I have I got this on my screen:
Great, then I can actually create some virtual machines that are going to be LXC containers. The ClusterControl controller will do all the things for me:
When I issued the command to create the container the controller took over my wishes and started an internal job. The job would be performed without the help of the s9s command line program, but I used the --wait option to tell the s9s program to stay connected and monitor the execution of the job. When the job was finished the s9s exited and so I immediately could check the properties if the container.
There are tons of command line options, believe me, but the important thing is that one doesn't have to use them. The man pages are there, the options are available when you need them, but there is always an easy way to do things. The controller chose a container server, it chose a network, it chose everything because I told very little about my plans. It might not what I would do in a production environment, I would definitely specify what I want with a lot more details, but this is actually a good way to start playing with the containers.
Here is a way to delete a container, this time we monitor the job with the --log option, so we see the messages:
You can exit any time, the Ctrl+C works just fine, but that of course will not abort the job that is done by the ClusterControl controller server.
I can also unregister the container servers any time, the servers and the containers will of course remain. I can register the same server again whenever I like and the containers will appear again in the list so I can play with them once again:
Well, this about summarizes it, a few commands, a few command line options to create, use and delete containers. There are a lot more here, possibilities, options, logs, secret and public keys, privileges, owners and groups, networks and IP address ranges. A lot... for next time.