2018-07-26 12:45:10 -04:00
.. _containerCreation:
.. toctree ::
Creating Containers
___________________
2018-08-09 13:23:59 -04:00
Make sure you have gone through :ref: `installingVPP` on the system you want to create containers on.
2018-07-26 12:45:10 -04:00
2018-08-09 13:23:59 -04:00
After VPP is installed, get root privileges with:
2018-07-26 12:45:10 -04:00
2018-08-09 13:23:59 -04:00
.. code-block :: console
$ sudo bash
2018-07-26 12:45:10 -04:00
Then install packages for containers such as lxc:
2018-08-09 13:23:59 -04:00
.. code-block :: console
2018-07-26 12:45:10 -04:00
# apt-get install bridge-utils lxc
2023-10-30 18:47:36 +01:00
As quoted from the `lxc.conf manpage <https://linuxcontainers.org/lxc/manpages/man5/lxc.conf.5.html> `_ , "container configuration is held in the config stored in the container's directory.
2018-07-26 12:45:10 -04:00
A basic configuration is generated at container creation time with the default's recommended for the chosen template as well as extra default keys coming from the default.conf file."
"That *default.conf* file is either located at /etc/lxc/default.conf or for unprivileged containers at ~/.config/lxc/default.conf."
Since we want to ping between two containers, we'll need to **add to this file** .
Look at the contents of *default.conf* , which should initially look like this:
2018-08-09 13:23:59 -04:00
.. code-block :: console
2021-08-19 11:38:06 +02:00
2018-08-01 10:38:23 -04:00
# cat /etc/lxc/default.conf
2023-10-30 18:47:36 +01:00
lxc.net.0.type = veth
lxc.net.0.link = lxcbr0
lxc.net.0.flags = up
lxc.net.0.hwaddr = 00:16:3e:xx:xx:xx
2018-07-26 12:45:10 -04:00
As you can see, by default there is one veth interface.
Now you will *append to this file* so that each container you create will have an interface for a Linux bridge and an unconsumed second interface.
2021-08-19 11:38:06 +02:00
You can do this by piping *echo* output into *tee* , where each line is separated with a newline character *\\n* as shown below. Alternatively, you can manually add to this file with a text editor such as **vi** , but make sure you have root privileges.
2018-07-26 12:45:10 -04:00
2018-08-09 13:23:59 -04:00
.. code-block :: console
2018-07-26 12:45:10 -04:00
2023-10-30 18:47:36 +01:00
# echo -e "lxc.net.0.name = veth0\nlxc.net.1.type = veth\nlxc.net.1.name = veth_link1" | sudo tee -a /etc/lxc/default.conf
2018-07-26 12:45:10 -04:00
Inspect the contents again to verify the file was indeed modified:
2018-08-09 13:23:59 -04:00
.. code-block :: console
2018-07-26 12:45:10 -04:00
2018-08-01 10:38:23 -04:00
# cat /etc/lxc/default.conf
2023-10-30 18:47:36 +01:00
lxc.net.0.type = veth
lxc.net.0.link = lxcbr0
lxc.net.0.flags = up
lxc.net.0.hwaddr = 00:16:3e:xx:xx:xx
lxc.net.0.name = veth0
lxc.net.1.type = veth
lxc.net.1.name = veth_link
2018-07-26 12:45:10 -04:00
After this, we're ready to create the containers.
2023-10-30 18:47:36 +01:00
Creates an Ubuntu Focal container named "cone".
2018-07-26 12:45:10 -04:00
2018-08-09 13:23:59 -04:00
.. code-block :: console
2018-07-26 12:45:10 -04:00
2023-10-30 18:47:36 +01:00
# lxc-create -t download -n cone -- --dist ubuntu --release focal --arch amd64
2018-07-26 12:45:10 -04:00
If successful, you'll get an output similar to this:
.. code-block :: console
2021-08-19 11:38:06 +02:00
2023-10-30 18:47:36 +01:00
You just created an Ubuntu focal amd64 (20231027_07:42) container.
2018-07-26 12:45:10 -04:00
To enable SSH, run: apt install openssh-server
No default root or user password are set by LXC.
Make another container "ctwo".
2018-08-09 13:23:59 -04:00
.. code-block :: console
2018-07-26 12:45:10 -04:00
2023-10-30 18:47:36 +01:00
# lxc-create -t download -n ctwo -- --dist ubuntu --release focal --arch amd64
2018-07-26 12:45:10 -04:00
List your containers to verify they exist:
2018-08-09 13:23:59 -04:00
.. code-block :: console
2018-07-26 12:45:10 -04:00
# lxc-ls
cone ctwo
Start the first container:
2018-08-09 13:23:59 -04:00
.. code-block :: console
2021-08-19 11:38:06 +02:00
2018-07-26 12:45:10 -04:00
# lxc-start --name cone
And verify its running:
2018-08-09 13:23:59 -04:00
.. code-block :: console
2021-08-19 11:38:06 +02:00
2018-07-26 12:45:10 -04:00
# lxc-ls --fancy
2023-10-30 18:47:36 +01:00
NAME STATE AUTOSTART GROUPS IPV4 IPV6 UNPRIVILEGED
cone RUNNING 0 - - - false
ctwo STOPPED 0 - - - false
2018-07-26 12:45:10 -04:00
.. note ::
Here are some `lxc container commands <https://help.ubuntu.com/lts/serverguide/lxc.html.en-GB#lxc-basic-usage> `_ you may find useful:
2018-08-09 13:23:59 -04:00
.. code-block :: console
2018-07-26 12:45:10 -04:00
2018-08-09 13:23:59 -04:00
$ sudo lxc-ls --fancy
$ sudo lxc-start --name u1 --daemon
$ sudo lxc-info --name u1
$ sudo lxc-stop --name u1
$ sudo lxc-destroy --name u1