blob: bb116883e7d3a130ce7240f35bee2daed3198812 [file] [log] [blame]
John DeNisco06dcd452018-07-26 12:45:10 -04001.. _containerCreation:
2
3.. toctree::
4
5Creating Containers
6___________________
7
andrewdf50b452018-08-09 13:23:59 -04008Make sure you have gone through :ref:`installingVPP` on the system you want to create containers on.
John DeNisco06dcd452018-07-26 12:45:10 -04009
andrewdf50b452018-08-09 13:23:59 -040010After VPP is installed, get root privileges with:
John DeNisco06dcd452018-07-26 12:45:10 -040011
andrewdf50b452018-08-09 13:23:59 -040012.. code-block:: console
13
14 $ sudo bash
John DeNisco06dcd452018-07-26 12:45:10 -040015
16Then install packages for containers such as lxc:
17
andrewdf50b452018-08-09 13:23:59 -040018.. code-block:: console
John DeNisco06dcd452018-07-26 12:45:10 -040019
20 # apt-get install bridge-utils lxc
21
22As quoted from the `lxc.conf manpage <https://linuxcontainers.org/it/lxc/manpages/man5/lxc.conf.5.html>`_, "container configuration is held in the config stored in the container's directory.
23A 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."
24
25"That *default.conf* file is either located at /etc/lxc/default.conf or for unprivileged containers at ~/.config/lxc/default.conf."
26
27Since we want to ping between two containers, we'll need to **add to this file**.
28
29Look at the contents of *default.conf*, which should initially look like this:
30
andrewdf50b452018-08-09 13:23:59 -040031.. code-block:: console
Nathan Skrzypczak9ad39c02021-08-19 11:38:06 +020032
John DeNiscoa14c1662018-08-01 10:38:23 -040033 # cat /etc/lxc/default.conf
John DeNisco06dcd452018-07-26 12:45:10 -040034 lxc.network.type = veth
35 lxc.network.link = lxcbr0
36 lxc.network.flags = up
37 lxc.network.hwaddr = 00:16:3e:xx:xx:xx
38
39As you can see, by default there is one veth interface.
40
41Now 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.
42
Nathan Skrzypczak9ad39c02021-08-19 11:38:06 +020043You 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.
John DeNisco06dcd452018-07-26 12:45:10 -040044
andrewdf50b452018-08-09 13:23:59 -040045.. code-block:: console
John DeNisco06dcd452018-07-26 12:45:10 -040046
47 # echo -e "lxc.network.name = veth0\nlxc.network.type = veth\nlxc.network.name = veth_link1" | sudo tee -a /etc/lxc/default.conf
48
49Inspect the contents again to verify the file was indeed modified:
50
andrewdf50b452018-08-09 13:23:59 -040051.. code-block:: console
John DeNisco06dcd452018-07-26 12:45:10 -040052
John DeNiscoa14c1662018-08-01 10:38:23 -040053 # cat /etc/lxc/default.conf
John DeNisco06dcd452018-07-26 12:45:10 -040054 lxc.network.type = veth
55 lxc.network.link = lxcbr0
56 lxc.network.flags = up
57 lxc.network.hwaddr = 00:16:3e:xx:xx:xx
58 lxc.network.name = veth0
59 lxc.network.type = veth
60 lxc.network.name = veth_link1
61
62
63After this, we're ready to create the containers.
64
65Creates an Ubuntu Xenial container named "cone".
66
andrewdf50b452018-08-09 13:23:59 -040067.. code-block:: console
John DeNisco06dcd452018-07-26 12:45:10 -040068
69 # lxc-create -t download -n cone -- --dist ubuntu --release xenial --arch amd64 --keyserver hkp://p80.pool.sks-keyservers.net:80
70
71
72If successful, you'll get an output similar to this:
73
74.. code-block:: console
Nathan Skrzypczak9ad39c02021-08-19 11:38:06 +020075
John DeNisco06dcd452018-07-26 12:45:10 -040076 You just created an Ubuntu xenial amd64 (20180625_07:42) container.
77
78 To enable SSH, run: apt install openssh-server
79 No default root or user password are set by LXC.
80
81
82Make another container "ctwo".
83
andrewdf50b452018-08-09 13:23:59 -040084.. code-block:: console
John DeNisco06dcd452018-07-26 12:45:10 -040085
86 # lxc-create -t download -n ctwo -- --dist ubuntu --release xenial --arch amd64 --keyserver hkp://p80.pool.sks-keyservers.net:80
87
88
89List your containers to verify they exist:
90
91
andrewdf50b452018-08-09 13:23:59 -040092.. code-block:: console
John DeNisco06dcd452018-07-26 12:45:10 -040093
94 # lxc-ls
95 cone ctwo
96
97
98Start the first container:
99
andrewdf50b452018-08-09 13:23:59 -0400100.. code-block:: console
Nathan Skrzypczak9ad39c02021-08-19 11:38:06 +0200101
John DeNisco06dcd452018-07-26 12:45:10 -0400102 # lxc-start --name cone
103
104And verify its running:
105
andrewdf50b452018-08-09 13:23:59 -0400106.. code-block:: console
Nathan Skrzypczak9ad39c02021-08-19 11:38:06 +0200107
John DeNisco06dcd452018-07-26 12:45:10 -0400108 # lxc-ls --fancy
Nathan Skrzypczak9ad39c02021-08-19 11:38:06 +0200109 NAME STATE AUTOSTART GROUPS IPV4 IPV6
110 cone RUNNING 0 - - -
111 ctwo STOPPED 0 - - -
John DeNisco06dcd452018-07-26 12:45:10 -0400112
113
114.. note::
115
116 Here are some `lxc container commands <https://help.ubuntu.com/lts/serverguide/lxc.html.en-GB#lxc-basic-usage>`_ you may find useful:
117
118
andrewdf50b452018-08-09 13:23:59 -0400119 .. code-block:: console
John DeNisco06dcd452018-07-26 12:45:10 -0400120
andrewdf50b452018-08-09 13:23:59 -0400121 $ sudo lxc-ls --fancy
122 $ sudo lxc-start --name u1 --daemon
123 $ sudo lxc-info --name u1
124 $ sudo lxc-stop --name u1
125 $ sudo lxc-destroy --name u1