{"id":6260,"date":"2019-02-19T09:45:46","date_gmt":"2019-02-19T15:45:46","guid":{"rendered":"https:\/\/www.poweradmin.com\/blog\/?p=6260"},"modified":"2019-02-19T14:55:04","modified_gmt":"2019-02-19T20:55:04","slug":"best-practices-for-configuring-linux-containers","status":"publish","type":"post","link":"https:\/\/www.poweradmin.com\/blog\/best-practices-for-configuring-linux-containers\/","title":{"rendered":"Best Practices for Configuring Linux Containers"},"content":{"rendered":"<p style=\"margin: 0px; line-height: 150%;\"><span style=\"color: #000000;\"><strong><span style=\"margin: 0px; font-family: 'Arial',sans-serif;\">By Des Nnochiri<\/span><\/strong><\/span><\/p>\n<p>\u00a0<\/p>\n<p style=\"margin: 0px; line-height: 150%;\"><span style=\"margin: 0px; font-family: 'Arial',sans-serif;\">Within a Linux network or development system, launching a limited set of applications or services (often known as microservices) in a self-sustaining container or sandboxed environment is sometimes necessary. A container enables administrators to decouple a specific set of software applications from the operating system and have them run within a clean, minimal, and isolated Linux environment of their own. <\/span><\/p>\n<p style=\"margin: 0px; line-height: 150%;\"><span style=\"margin: 0px; font-family: 'Arial',sans-serif;\">\u00a0<\/span><\/p>\n<p style=\"margin: 0px; line-height: 150%;\"><span style=\"margin: 0px; font-family: 'Arial',sans-serif;\">All the files required to run a Linux container are sourced from a distinct image, so Linux containers remain portable and consistent as they move from development, through to testing, and ultimately to production. The contents of a container image can be thought of as an isolated installation of a Linux distribution\u2014complete with RPM packages, configuration files, libraries, dependencies, and so on. Maintaining this isolation is a critical part of preserving the integrity of each container. <\/span><\/p>\n<p style=\"margin: 0px; line-height: 150%;\"><span style=\"margin: 0px; font-family: 'Arial',sans-serif;\">\u00a0<\/span><\/p>\n<p style=\"text-align: center;\"><a href=\"https:\/\/www.poweradmin.com\/blog\/wp-content\/uploads\/2019\/02\/linux-operating-systems.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-6263\" src=\"https:\/\/www.poweradmin.com\/blog\/wp-content\/uploads\/2019\/02\/linux-operating-systems-300x135.png\" alt=\"\" width=\"450\" height=\"202\" srcset=\"https:\/\/www.poweradmin.com\/blog\/wp-content\/uploads\/2019\/02\/linux-operating-systems-300x135.png 300w, https:\/\/www.poweradmin.com\/blog\/wp-content\/uploads\/2019\/02\/linux-operating-systems.png 557w\" sizes=\"auto, (max-width: 450px) 100vw, 450px\"><\/a><\/p>\n<p>\u00a0<\/p>\n<p style=\"margin: 0px; text-align: center; line-height: 150%;\"><span style=\"margin: 0px; font-family: 'Arial',sans-serif;\">(Image Source: <span style=\"margin: 0px;\"><a href=\"https:\/\/www.linuxjournal.com\/content\/everything-you-need-know-about-linux-containers-part-ii-working-linux-containers-lxc\" rel=\"nofollow\" target=\"_blank\">Linux Journal<img class=\"extlink-icon\" src=\"https:\/\/www.poweradmin.com\/blog\/wp-content\/plugins\/external-links-nofollow-open-in-new-tab-favicon\/images\/extlink.png\"><\/a><\/span>)<\/span><\/p>\n<p style=\"margin: 0px; line-height: 150%;\"><span style=\"margin: 0px; font-family: 'Arial',sans-serif;\">\u00a0<\/span><\/p>\n<p style=\"margin: 0px; line-height: 150%;\"><span style=\"margin: 0px; font-family: 'Arial',sans-serif;\">\u00a0<\/span><\/p>\n<h2 style=\"margin: 13.33px 0px 0px;\"><span style=\"margin: 0px; font-family: 'Arial',sans-serif;\">Ensuring Isolation<\/span><\/h2>\n<p style=\"margin: 0px; line-height: 150%;\"><span style=\"margin: 0px; font-family: 'Arial',sans-serif;\">\u00a0<\/span><\/p>\n<p style=\"margin: 0px; line-height: 150%;\"><span style=\"margin: 0px; font-family: 'Arial',sans-serif;\">Processes running within a properly-configured container are prevented from monitoring or affecting processes running in another. If isolation is properly maintained, then containerized services should also not influence or disturb the host machine.<span style=\"margin: 0px;\">\u00a0 <\/span><\/span><\/p>\n<p style=\"margin: 0px; line-height: 150%;\"><span style=\"margin: 0px; font-family: 'Arial',sans-serif;\">\u00a0<\/span><\/p>\n<p style=\"margin: 0px; line-height: 150%;\"><span style=\"margin: 0px; font-family: 'Arial',sans-serif;\">Control groups, or cgroups, are a Linux kernel feature that controls and limits the resource usage for a process or for groups of processes. The cgroups feature makes use of an initialization system known as systemd, which sets up the user space and manages the isolated processes.<\/span><\/p>\n<p style=\"margin: 0px; line-height: 150%;\"><span style=\"margin: 0px; font-family: 'Arial',sans-serif;\">\u00a0<\/span><\/p>\n<p style=\"margin: 0px; line-height: 150%;\"><span style=\"margin: 0px; font-family: 'Arial',sans-serif;\">Kernel namespaces allow a variety of identities to be virtualized within the Linux kernel, including process IDs, network names, and user namespaces\u2014which ensure that users and groups enjoying privileges for certain operations inside the container can be denied those rights outside the container.<\/span><\/p>\n<p style=\"margin: 0px; line-height: 150%;\"><span style=\"margin: 0px; font-family: 'Arial',sans-serif;\">\u00a0<\/span><\/p>\n<h2 style=\"margin: 13.33px 0px 0px;\"><span style=\"margin: 0px; font-family: 'Arial',sans-serif;\">Laying the Groundwork for Container Creation<\/span><\/h2>\n<p style=\"margin: 0px; line-height: 150%;\"><span style=\"margin: 0px; font-family: 'Arial',sans-serif;\">\u00a0<\/span><\/p>\n<p style=\"margin: 0px; line-height: 150%;\"><span style=\"margin: 0px; font-family: 'Arial',sans-serif;\">Before configuring the Linux environment, you\u2019ll need to verify that the current user has both a uid and gid entry defined in \/etc\/subuid and \/etc\/subgid. <a href=\"https:\/\/www.linuxjournal.com\/content\/everything-you-need-know-about-linux-containers-part-ii-working-linux-containers-lxc\" rel=\"nofollow\" target=\"_blank\">Writing for Linux Journal<img class=\"extlink-icon\" src=\"https:\/\/www.poweradmin.com\/blog\/wp-content\/plugins\/external-links-nofollow-open-in-new-tab-favicon\/images\/extlink.png\"><\/a><span style=\"margin: 0px;\"><span style=\"margin: 0px; color: windowtext; text-decoration: none;\"><u>,<\/u> Petros Koutoupis<\/span><\/span> offers the following example (together with the screenshots and other syntax instances quoted in this article):<\/span><\/p>\n<p style=\"margin: 0px; line-height: 150%;\"><span style=\"margin: 0px; font-family: 'Arial',sans-serif;\">\u00a0<\/span><\/p>\n<p style=\"margin: 0px; line-height: 150%;\"><span style=\"margin: 0px; font-family: 'Arial',sans-serif;\">$ cat \/etc\/subuid<\/span><\/p>\n<p style=\"margin: 0px; line-height: 150%;\"><span style=\"margin: 0px; font-family: 'Arial',sans-serif;\">petros:100000:65536<\/span><\/p>\n<p style=\"margin: 0px; line-height: 150%;\"><span style=\"margin: 0px; font-family: 'Arial',sans-serif;\">$ cat \/etc\/subgid<\/span><\/p>\n<p style=\"margin: 0px; line-height: 150%;\"><span style=\"margin: 0px; font-family: 'Arial',sans-serif;\">petros:100000:65536<\/span><\/p>\n<p style=\"margin: 0px; line-height: 150%;\"><span style=\"margin: 0px; font-family: 'Arial',sans-serif;\">\u00a0<\/span><\/p>\n<h2 style=\"margin: 13.33px 0px 0px;\"><span style=\"margin: 0px; font-family: 'Arial',sans-serif;\">Configuring the Linux Environment for Containers<\/span><\/h2>\n<p style=\"margin: 0px; line-height: 150%;\"><span style=\"margin: 0px; font-family: 'Arial',sans-serif;\">\u00a0<\/span><\/p>\n<p style=\"margin: 0px; line-height: 150%;\"><span style=\"margin: 0px; font-family: 'Arial',sans-serif;\">if it doesn\u2019t already exist, you\u2019ll need to create the ~\/.config\/lxc directory, then copy the configuration file \/etc\/lxc\/default.conf to ~\/.config\/lxc\/default.conf. The following:<\/span><\/p>\n<p style=\"margin: 0px; line-height: 150%;\"><span style=\"margin: 0px; font-family: 'Arial',sans-serif;\">\u00a0<\/span><\/p>\n<p style=\"margin: 0px; line-height: 150%;\"><span style=\"margin: 0px; font-family: 'Arial',sans-serif;\">lxc.id_map = u 0 100000 65536<\/span><\/p>\n<p style=\"margin: 0px; line-height: 150%;\"><span style=\"margin: 0px; font-family: 'Arial',sans-serif;\">lxc.id_map = g 0 100000 65536<\/span><\/p>\n<p style=\"margin: 0px; line-height: 150%;\"><span style=\"margin: 0px; font-family: 'Arial',sans-serif;\">\u00a0<\/span><\/p>\n<p style=\"margin: 0px; line-height: 150%;\"><span style=\"margin: 0px; font-family: 'Arial',sans-serif;\">should be added to the end of the file, which will be of the form:<\/span><\/p>\n<p style=\"margin: 0px; line-height: 150%;\"><span style=\"margin: 0px; font-family: 'Arial',sans-serif;\">\u00a0<\/span><\/p>\n<p style=\"margin: 0px; line-height: 150%;\"><span style=\"margin: 0px; font-family: 'Arial',sans-serif;\">$ cat ~\/.config\/lxc\/default.conf<\/span><\/p>\n<p style=\"margin: 0px; line-height: 150%;\"><span style=\"margin: 0px; font-family: 'Arial',sans-serif;\">lxc.network.type = veth<\/span><\/p>\n<p style=\"margin: 0px; line-height: 150%;\"><span style=\"margin: 0px; font-family: 'Arial',sans-serif;\">lxc.network.link = lxcbr0<\/span><\/p>\n<p style=\"margin: 0px; line-height: 150%;\"><span style=\"margin: 0px; font-family: 'Arial',sans-serif;\">lxc.network.flags = up<\/span><\/p>\n<p style=\"margin: 0px; line-height: 150%;\"><span style=\"margin: 0px; font-family: 'Arial',sans-serif;\">lxc.network.hwaddr = 00:16:3e:xx:xx:xx<\/span><\/p>\n<p style=\"margin: 0px; line-height: 150%;\"><span style=\"margin: 0px; font-family: 'Arial',sans-serif;\">lxc.id_map = u 0 100000 65536<\/span><\/p>\n<p style=\"margin: 0px; line-height: 150%;\"><span style=\"margin: 0px; font-family: 'Arial',sans-serif;\">lxc.id_map = g 0 100000 65536<\/span><\/p>\n<p style=\"margin: 0px; line-height: 150%;\"><span style=\"margin: 0px; font-family: 'Arial',sans-serif;\">\u00a0<\/span><\/p>\n<p style=\"margin: 0px; line-height: 150%;\"><span style=\"margin: 0px; font-family: 'Arial',sans-serif;\">Replace the first column of the \/etc\/lxc\/lxc-usernet file with your user name (e.g., petros veth lxcbr0 10). Then either reboot the node or log the user out and then back in.<\/span><\/p>\n<p style=\"margin: 0px; line-height: 150%;\"><span style=\"margin: 0px; font-family: 'Arial',sans-serif;\">\u00a0<\/span><\/p>\n<p style=\"margin: 0px; line-height: 150%;\"><span style=\"margin: 0px; font-family: 'Arial',sans-serif;\">To verify that the veth networking driver is currently loaded, type the following:<\/span><\/p>\n<p style=\"margin: 0px; line-height: 150%;\"><span style=\"margin: 0px; font-family: 'Arial',sans-serif;\">\u00a0<\/span><\/p>\n<p style=\"margin: 0px; line-height: 150%;\"><span style=\"margin: 0px; font-family: 'Arial',sans-serif;\">$ lsmod|grep veth<\/span><\/p>\n<p style=\"margin: 0px; line-height: 150%;\"><span style=\"margin: 0px; font-family: 'Arial',sans-serif;\">veth<span style=\"margin: 0px;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 <\/span>16384<span style=\"margin: 0px;\">\u00a0 <\/span>0<\/span><\/p>\n<p style=\"margin: 0px; line-height: 150%;\"><span style=\"margin: 0px; font-family: 'Arial',sans-serif;\">\u00a0<\/span><\/p>\n<p style=\"margin: 0px; line-height: 150%;\"><span style=\"margin: 0px; font-family: 'Arial',sans-serif;\">If the driver has not been loaded yet, use:<\/span><\/p>\n<p style=\"margin: 0px; line-height: 150%;\"><span style=\"margin: 0px; font-family: 'Arial',sans-serif;\">\u00a0<\/span><\/p>\n<p style=\"margin: 0px; line-height: 150%;\"><span style=\"margin: 0px; font-family: 'Arial',sans-serif;\">$ sudo modprobe veth<\/span><\/p>\n<p style=\"margin: 0px; line-height: 150%;\"><span style=\"margin: 0px; font-family: 'Arial',sans-serif;\">\u00a0<\/span><\/p>\n<h2 style=\"margin: 13.33px 0px 0px;\"><span style=\"margin: 0px; font-family: 'Arial',sans-serif;\">Managing Containers with the LXC Utilities <\/span><\/h2>\n<p style=\"margin: 0px; line-height: 150%;\"><span style=\"margin: 0px; font-family: 'Arial',sans-serif;\">\u00a0<\/span><\/p>\n<p style=\"margin: 0px; line-height: 150%;\"><span style=\"margin: 0px; font-family: 'Arial',sans-serif;\">The Linux Containers project (LXC) provides tools, templates, libraries, and language bindings to improve the user experience when downloading, running, and managing containers. The LXC utilities employ a simple command line, but in order to use them, you need to install them first.<\/span><\/p>\n<p style=\"margin: 0px; line-height: 150%;\"><span style=\"margin: 0px; font-family: 'Arial',sans-serif;\">\u00a0<\/span><\/p>\n<p style=\"margin: 0px; line-height: 150%;\"><span style=\"margin: 0px; font-family: 'Arial',sans-serif;\">Before the installation on Red Hat Linux or CentOS, you\u2019ll first have to install the EPEL repositories. Distributions like Ubuntu or Debian will complete the LXC installation simply through typing:<\/span><\/p>\n<p style=\"margin: 0px; line-height: 150%;\"><span style=\"margin: 0px; font-family: 'Arial',sans-serif;\">\u00a0<\/span><\/p>\n<p style=\"margin: 0px; line-height: 150%;\"><span style=\"margin: 0px; font-family: 'Arial',sans-serif;\">$ sudo apt-get install lxc<\/span><\/p>\n<p style=\"margin: 0px; line-height: 150%;\"><span style=\"margin: 0px; font-family: 'Arial',sans-serif;\">\u00a0<\/span><\/p>\n<h2 style=\"margin: 13.33px 0px 0px;\"><span style=\"margin: 0px; font-family: 'Arial',sans-serif;\">Downloading a Container<\/span><\/h2>\n<p style=\"margin: 0px; line-height: 150%;\"><span style=\"margin: 0px; font-family: 'Arial',sans-serif;\"><span style=\"margin: 0px;\">\u00a0<\/span><\/span><\/p>\n<p style=\"margin: 0px; line-height: 150%;\"><span style=\"margin: 0px; font-family: 'Arial',sans-serif;\">The following command may be used to download a container image named \u201cexample-container\u201d:<\/span><\/p>\n<p style=\"margin: 0px; line-height: 150%;\"><span style=\"margin: 0px; font-family: 'Arial',sans-serif;\">\u00a0<\/span><\/p>\n<p style=\"margin: 0px; line-height: 150%;\"><span style=\"margin: 0px; font-family: 'Arial',sans-serif;\">$ sudo lxc-create -t download -n example-container<\/span><\/p>\n<p style=\"margin: 0px; line-height: 150%;\"><span style=\"margin: 0px; font-family: 'Arial',sans-serif;\">\u00a0<\/span><\/p>\n<p style=\"margin: 0px; line-height: 150%;\"><span style=\"margin: 0px; font-family: 'Arial',sans-serif;\">The LXC utilities will display three prompts, inviting you to choose the container\u2019s Linux distribution, release, and architecture. For example:<\/span><\/p>\n<p style=\"margin: 0px; line-height: 150%;\"><span style=\"margin: 0px; font-family: 'Arial',sans-serif;\">\u00a0<\/span><\/p>\n<p style=\"margin: 0px; line-height: 150%;\"><span style=\"margin: 0px; font-family: 'Arial',sans-serif;\">Distribution: ubuntu<\/span><\/p>\n<p style=\"margin: 0px; line-height: 150%;\"><span style=\"margin: 0px; font-family: 'Arial',sans-serif;\">Release: xenial<\/span><\/p>\n<p style=\"margin: 0px; line-height: 150%;\"><span style=\"margin: 0px; font-family: 'Arial',sans-serif;\">Architecture: amd64<\/span><\/p>\n<p style=\"margin: 0px; line-height: 150%;\"><span style=\"margin: 0px; font-family: 'Arial',sans-serif;\">\u00a0<\/span><\/p>\n<p style=\"margin: 0px; line-height: 150%;\"><span style=\"margin: 0px; font-family: 'Arial',sans-serif;\">Once you press Enter, the rootfs of the selected container will be downloaded locally and configured.<\/span><\/p>\n<p style=\"margin: 0px; line-height: 150%;\"><span style=\"margin: 0px; font-family: 'Arial',sans-serif;\">\u00a0<\/span><\/p>\n<h2 style=\"margin: 13.33px 0px 0px;\"><span style=\"margin: 0px; font-family: 'Arial',sans-serif;\">Starting a Container<\/span><\/h2>\n<p style=\"margin: 0px; line-height: 150%;\"><span style=\"margin: 0px; font-family: 'Arial',sans-serif;\">\u00a0<\/span><\/p>\n<p style=\"margin: 0px; line-height: 150%;\"><span style=\"margin: 0px; font-family: 'Arial',sans-serif;\">To start the container, type:<\/span><\/p>\n<p style=\"margin: 0px; line-height: 150%;\"><span style=\"margin: 0px; font-family: 'Arial',sans-serif;\">\u00a0<\/span><\/p>\n<p style=\"margin: 0px; line-height: 150%;\"><span style=\"margin: 0px; font-family: 'Arial',sans-serif;\">$ sudo lxc-start -n example-container -d<\/span><\/p>\n<p style=\"margin: 0px; line-height: 150%;\"><span style=\"margin: 0px; font-family: 'Arial',sans-serif;\">\u00a0<\/span><\/p>\n<p style=\"margin: 0px; line-height: 150%;\"><span style=\"margin: 0px; font-family: 'Arial',sans-serif;\">Using the -d option d\u00e6monizes the container and sets it to run in the background. The foreground option (where you can observer the container\u2019s boot process and be prompted to log in) may be denoted by the -F qualifier. <\/span><\/p>\n<p style=\"margin: 0px; line-height: 150%;\"><span style=\"margin: 0px; font-family: 'Arial',sans-serif;\">\u00a0<\/span><\/p>\n<h2 style=\"margin: 13.33px 0px 0px;\"><span style=\"margin: 0px; font-family: 'Arial',sans-serif;\">Troubleshooting Tips<\/span><\/h2>\n<p style=\"margin: 0px; line-height: 150%;\"><span style=\"margin: 0px; font-family: 'Arial',sans-serif;\">\u00a0<\/span><\/p>\n<p style=\"margin: 0px; line-height: 150%;\"><span style=\"margin: 0px; font-family: 'Arial',sans-serif;\">The screenshot below illustrates the kind of syntax you can use to deploy the LXC utilities troubleshooting tools, if any glitches are encountered; for example, if a container fails to initiate properly:<\/span><\/p>\n<p>\u00a0<\/p>\n<p style=\"text-align: center;\"><a href=\"https:\/\/www.poweradmin.com\/blog\/wp-content\/uploads\/2019\/02\/linux-journal-1.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-6266\" src=\"https:\/\/www.poweradmin.com\/blog\/wp-content\/uploads\/2019\/02\/linux-journal-1-300x144.png\" alt=\"\" width=\"450\" height=\"216\" srcset=\"https:\/\/www.poweradmin.com\/blog\/wp-content\/uploads\/2019\/02\/linux-journal-1-300x144.png 300w, https:\/\/www.poweradmin.com\/blog\/wp-content\/uploads\/2019\/02\/linux-journal-1-768x369.png 768w, https:\/\/www.poweradmin.com\/blog\/wp-content\/uploads\/2019\/02\/linux-journal-1.png 848w\" sizes=\"auto, (max-width: 450px) 100vw, 450px\"><\/a><\/p>\n<p style=\"margin: 0px; line-height: 150%;\"><span style=\"margin: 0px; font-family: 'Arial',sans-serif;\">\u00a0<\/span><\/p>\n<p style=\"margin: 0px; text-align: center; line-height: 150%;\"><span style=\"margin: 0px; font-family: 'Arial',sans-serif;\">(Image Source: <span style=\"margin: 0px;\"><a href=\"https:\/\/www.linuxjournal.com\/content\/everything-you-need-know-about-linux-containers-part-ii-working-linux-containers-lxc\" rel=\"nofollow\" target=\"_blank\">Linux Journal<img class=\"extlink-icon\" src=\"https:\/\/www.poweradmin.com\/blog\/wp-content\/plugins\/external-links-nofollow-open-in-new-tab-favicon\/images\/extlink.png\"><\/a><\/span>)<\/span><\/p>\n<p style=\"margin: 0px; line-height: 150%;\"><span style=\"margin: 0px; font-family: 'Arial',sans-serif;\">\u00a0<\/span><\/p>\n<p style=\"margin: 0px; line-height: 150%;\"><span style=\"margin: 0px; font-family: 'Arial',sans-serif;\">There\u2019s a diagnostic facility which allows you to check the current status of a given container:<\/span><\/p>\n<p style=\"margin: 0px; line-height: 150%;\"><span style=\"margin: 0px; font-family: 'Arial',sans-serif;\">\u00a0<\/span><\/p>\n<p style=\"text-align: center;\"><a href=\"https:\/\/www.poweradmin.com\/blog\/wp-content\/uploads\/2019\/02\/linux-journal-2.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-6269\" src=\"https:\/\/www.poweradmin.com\/blog\/wp-content\/uploads\/2019\/02\/linux-journal-2-300x136.png\" alt=\"\" width=\"450\" height=\"204\" srcset=\"https:\/\/www.poweradmin.com\/blog\/wp-content\/uploads\/2019\/02\/linux-journal-2-300x136.png 300w, https:\/\/www.poweradmin.com\/blog\/wp-content\/uploads\/2019\/02\/linux-journal-2-768x348.png 768w, https:\/\/www.poweradmin.com\/blog\/wp-content\/uploads\/2019\/02\/linux-journal-2.png 847w\" sizes=\"auto, (max-width: 450px) 100vw, 450px\"><\/a><\/p>\n<p>\u00a0<\/p>\n<p style=\"margin: 0px; text-align: center; line-height: 150%;\"><span style=\"margin: 0px; font-family: 'Arial',sans-serif;\">(Image Source: <span style=\"margin: 0px;\"><a href=\"https:\/\/www.linuxjournal.com\/content\/everything-you-need-know-about-linux-containers-part-ii-working-linux-containers-lxc\" rel=\"nofollow\" target=\"_blank\">Linux Journal<img class=\"extlink-icon\" src=\"https:\/\/www.poweradmin.com\/blog\/wp-content\/plugins\/external-links-nofollow-open-in-new-tab-favicon\/images\/extlink.png\"><\/a><\/span>)<\/span><\/p>\n<p style=\"margin: 0px; line-height: 150%;\"><span style=\"margin: 0px; font-family: 'Arial',sans-serif;\"><span style=\"margin: 0px;\">\u00a0<\/span><\/span><\/p>\n<p style=\"margin: 0px; line-height: 150%;\"><span style=\"margin: 0px; font-family: 'Arial',sans-serif;\">You can also do this from the command line by typing the following, which lists all of the installed containers:<\/span><\/p>\n<p style=\"margin: 0px; line-height: 150%;\"><span style=\"margin: 0px; font-family: 'Arial',sans-serif;\">\u00a0<\/span><\/p>\n<p style=\"margin: 0px; line-height: 150%;\"><span style=\"margin: 0px; font-family: 'Arial',sans-serif;\">$ sudo lxc-ls -f<\/span><\/p>\n<p style=\"margin: 0px; line-height: 150%;\"><span style=\"margin: 0px; font-family: 'Arial',sans-serif;\">NAME<span style=\"margin: 0px;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 <\/span>STATE<span style=\"margin: 0px;\">\u00a0\u00a0 <\/span>AUTOSTART GROUPS IPV4<span style=\"margin: 0px;\">\u00a0\u00a0\u00a0\u00a0\u00a0 <\/span>IPV6<\/span><\/p>\n<p style=\"margin: 0px; line-height: 150%;\"><span style=\"margin: 0px; font-family: 'Arial',sans-serif;\">example-container RUNNING 0<span style=\"margin: 0px;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 <\/span>\u2013<span style=\"margin: 0px;\">\u00a0\u00a0\u00a0\u00a0\u00a0 <\/span>10.0.3.28 \u2013<\/span><\/p>\n<p style=\"margin: 0px; line-height: 150%;\"><span style=\"margin: 0px; font-family: 'Arial',sans-serif;\">\u00a0<\/span><\/p>\n<h2 style=\"margin: 13.33px 0px 0px;\"><span style=\"margin: 0px; font-family: 'Arial',sans-serif;\">Assigning Access Rights<\/span><\/h2>\n<p style=\"margin: 0px; line-height: 150%;\"><span style=\"margin: 0px; font-family: 'Arial',sans-serif;\">\u00a0<\/span><\/p>\n<p style=\"margin: 0px; line-height: 150%;\"><span style=\"margin: 0px; font-family: 'Arial',sans-serif;\">The password command enables administrators to attach directly to the currently running container, create a list of authorized users, and assign or change their relevant passwords.<\/span><\/p>\n<p>\u00a0<\/p>\n<p style=\"text-align: center;\"><a href=\"https:\/\/www.poweradmin.com\/blog\/wp-content\/uploads\/2019\/02\/linux-journal-3.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-6270\" src=\"https:\/\/www.poweradmin.com\/blog\/wp-content\/uploads\/2019\/02\/linux-journal-3-300x85.png\" alt=\"\" width=\"450\" height=\"128\" srcset=\"https:\/\/www.poweradmin.com\/blog\/wp-content\/uploads\/2019\/02\/linux-journal-3-300x85.png 300w, https:\/\/www.poweradmin.com\/blog\/wp-content\/uploads\/2019\/02\/linux-journal-3-768x218.png 768w, https:\/\/www.poweradmin.com\/blog\/wp-content\/uploads\/2019\/02\/linux-journal-3.png 846w\" sizes=\"auto, (max-width: 450px) 100vw, 450px\"><\/a><\/p>\n<p style=\"margin: 0px; line-height: 150%;\"><span style=\"margin: 0px; font-family: 'Arial',sans-serif;\">\u00a0<\/span><\/p>\n<p style=\"margin: 0px; text-align: center; line-height: 150%;\"><span style=\"margin: 0px; font-family: 'Arial',sans-serif;\">(Image Source<span style=\"margin: 0px;\"><a href=\"https:\/\/www.linuxjournal.com\/content\/everything-you-need-know-about-linux-containers-part-ii-working-linux-containers-lxc\" rel=\"nofollow\" target=\"_blank\">: Linux Journal<img class=\"extlink-icon\" src=\"https:\/\/www.poweradmin.com\/blog\/wp-content\/plugins\/external-links-nofollow-open-in-new-tab-favicon\/images\/extlink.png\"><\/a><\/span>)<\/span><\/p>\n<p style=\"margin: 0px; line-height: 150%;\"><span style=\"margin: 0px; font-family: 'Arial',sans-serif;\">\u00a0<\/span><\/p>\n<p style=\"margin: 0px; line-height: 150%;\"><span style=\"margin: 0px; font-family: 'Arial',sans-serif;\">Oversight for administrators is also available on the host system (rather than from within a container itself), via the following syntax which may be used to observe which LXC processes have been initiated and are running after a container has been launched:<\/span><\/p>\n<p style=\"margin: 0px; line-height: 150%;\"><span style=\"margin: 0px; font-family: 'Arial',sans-serif;\">\u00a0<\/span><\/p>\n<p style=\"text-align: center;\"><a href=\"https:\/\/www.poweradmin.com\/blog\/wp-content\/uploads\/2019\/02\/linux-journal-4.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-6271\" src=\"https:\/\/www.poweradmin.com\/blog\/wp-content\/uploads\/2019\/02\/linux-journal-4-300x172.png\" alt=\"\" width=\"450\" height=\"259\" srcset=\"https:\/\/www.poweradmin.com\/blog\/wp-content\/uploads\/2019\/02\/linux-journal-4-300x172.png 300w, https:\/\/www.poweradmin.com\/blog\/wp-content\/uploads\/2019\/02\/linux-journal-4-768x441.png 768w, https:\/\/www.poweradmin.com\/blog\/wp-content\/uploads\/2019\/02\/linux-journal-4.png 844w\" sizes=\"auto, (max-width: 450px) 100vw, 450px\"><\/a><\/p>\n<p>\u00a0<\/p>\n<p style=\"margin: 0px; text-align: center; line-height: 150%;\"><span style=\"margin: 0px; font-family: 'Arial',sans-serif;\">(Image Source: <span style=\"margin: 0px;\"><a href=\"https:\/\/www.linuxjournal.com\/content\/everything-you-need-know-about-linux-containers-part-ii-working-linux-containers-lxc\" rel=\"nofollow\" target=\"_blank\">Linux Journal<img class=\"extlink-icon\" src=\"https:\/\/www.poweradmin.com\/blog\/wp-content\/plugins\/external-links-nofollow-open-in-new-tab-favicon\/images\/extlink.png\"><\/a><\/span>)<\/span><\/p>\n<p style=\"margin: 0px; line-height: 150%;\"><span style=\"margin: 0px; font-family: 'Arial',sans-serif;\">\u00a0<\/span><\/p>\n<h2 style=\"margin: 13.33px 0px 0px;\"><span style=\"margin: 0px; font-family: 'Arial',sans-serif;\">Stopping a Container<\/span><\/h2>\n<p style=\"margin: 0px; line-height: 150%;\"><span style=\"margin: 0px; font-family: 'Arial',sans-serif;\">\u00a0<\/span><\/p>\n<p style=\"margin: 0px; line-height: 150%;\"><span style=\"margin: 0px; font-family: 'Arial',sans-serif;\">From the host machine, type:<\/span><\/p>\n<p style=\"margin: 0px; line-height: 150%;\"><span style=\"margin: 0px; font-family: 'Arial',sans-serif;\">\u00a0<\/span><\/p>\n<p style=\"margin: 0px; line-height: 150%;\"><span style=\"margin: 0px; font-family: 'Arial',sans-serif;\">$ sudo lxc-stop -n example-container<\/span><\/p>\n<p style=\"margin: 0px; line-height: 150%;\"><span style=\"margin: 0px; font-family: 'Arial',sans-serif;\">\u00a0<\/span><\/p>\n<p style=\"margin: 0px; line-height: 150%;\"><span style=\"margin: 0px; font-family: 'Arial',sans-serif;\">You can then verify the status of the stopped container, using:<\/span><\/p>\n<p style=\"margin: 0px; line-height: 150%;\"><span style=\"margin: 0px; font-family: 'Arial',sans-serif;\">\u00a0<\/span><\/p>\n<p style=\"margin: 0px; line-height: 150%;\"><span style=\"margin: 0px; font-family: 'Arial',sans-serif;\">$ sudo lxc-ls -f<\/span><\/p>\n<p style=\"margin: 0px; line-height: 150%;\"><span style=\"margin: 0px; font-family: 'Arial',sans-serif;\">NAME<span style=\"margin: 0px;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 <\/span>STATE<span style=\"margin: 0px;\">\u00a0\u00a0 <\/span>AUTOSTART GROUPS IPV4 IPV6<\/span><\/p>\n<p style=\"margin: 0px; line-height: 150%;\"><span style=\"margin: 0px; font-family: 'Arial',sans-serif;\">example-container STOPPED 0<span style=\"margin: 0px;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 <\/span>\u2013<span style=\"margin: 0px;\">\u00a0\u00a0\u00a0\u00a0\u00a0 <\/span>\u2013<span style=\"margin: 0px;\">\u00a0\u00a0\u00a0 <\/span>\u2013<\/span><\/p>\n<p style=\"margin: 0px; line-height: 150%;\"><span style=\"margin: 0px; font-family: 'Arial',sans-serif;\">\u00a0<\/span><\/p>\n<p style=\"margin: 0px; line-height: 150%;\"><span style=\"margin: 0px; font-family: 'Arial',sans-serif;\">$ sudo lxc-info -n example-container<\/span><\/p>\n<p style=\"margin: 0px; line-height: 150%;\"><span style=\"margin: 0px; font-family: 'Arial',sans-serif;\">Name:<span style=\"margin: 0px;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 <\/span>example-container<\/span><\/p>\n<p style=\"margin: 0px; line-height: 150%;\"><span style=\"margin: 0px; font-family: 'Arial',sans-serif;\">State:<span style=\"margin: 0px;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 <\/span>STOPPED<\/span><\/p>\n<p style=\"margin: 0px; line-height: 150%;\"><span style=\"margin: 0px; font-family: 'Arial',sans-serif;\">\u00a0<\/span><\/p>\n<h2 style=\"margin: 13.33px 0px 0px;\"><span style=\"margin: 0px; font-family: 'Arial',sans-serif;\">Destroying a Container<\/span><\/h2>\n<p style=\"margin: 0px; line-height: 150%;\"><span style=\"margin: 0px; font-family: 'Arial',sans-serif;\">\u00a0<\/span><\/p>\n<p style=\"margin: 0px; line-height: 150%;\"><span style=\"margin: 0px; font-family: 'Arial',sans-serif;\">Like any virtual environment, a container may be discarded once it has served its purpose. From the host system, type:<\/span><\/p>\n<p style=\"margin: 0px; line-height: 150%;\"><span style=\"margin: 0px; font-family: 'Arial',sans-serif;\">\u00a0<\/span><\/p>\n<p style=\"margin: 0px; line-height: 150%;\"><span style=\"margin: 0px; font-family: 'Arial',sans-serif;\">$ sudo lxc-destroy -n example-container<\/span><\/p>\n<p style=\"margin: 0px; line-height: 150%;\"><span style=\"margin: 0px; font-family: 'Arial',sans-serif;\">(The confirmation dialog will read: Destroyed container example-container)<\/span><\/p>\n<p style=\"margin: 0px; line-height: 150%;\"><span style=\"margin: 0px; font-family: 'Arial',sans-serif;\">\u00a0<\/span><\/p>\n<p style=\"margin: 0px; line-height: 150%;\"><span style=\"margin: 0px; font-family: 'Arial',sans-serif;\">The following command will verify that the selected container has actually been destroyed:<\/span><\/p>\n<p style=\"margin: 0px; line-height: 150%;\"><span style=\"margin: 0px; font-family: 'Arial',sans-serif;\">\u00a0<\/span><\/p>\n<p style=\"margin: 0px; line-height: 150%;\"><span style=\"margin: 0px; font-family: 'Arial',sans-serif;\">$ sudo lxc-info -n example-container<\/span><\/p>\n<p style=\"margin: 0px; line-height: 150%;\"><span style=\"margin: 0px; font-family: 'Arial',sans-serif;\">(example-container doesn\u2019t exist)<\/span><\/p>\n<p style=\"margin: 0px; line-height: 150%;\"><span style=\"margin: 0px; font-family: 'Arial',sans-serif;\">\u00a0<\/span><\/p>\n<p style=\"margin: 0px; line-height: 150%;\"><span style=\"margin: 0px; font-family: 'Arial',sans-serif;\">Note that a container has to be stopped before it can be destroyed.<\/span><\/p>\n<p style=\"margin: 0px; line-height: 150%;\"><span style=\"margin: 0px; font-family: 'Arial',sans-serif;\">\u00a0<\/span><\/p>\n<h2 style=\"margin: 13.33px 0px 0px;\"><span style=\"margin: 0px; font-family: 'Arial',sans-serif;\">Advanced Configuration Options<\/span><\/h2>\n<p style=\"margin: 0px; line-height: 150%;\"><span style=\"margin: 0px; font-family: 'Arial',sans-serif;\">\u00a0<\/span><\/p>\n<p style=\"margin: 0px; line-height: 150%;\"><span style=\"margin: 0px; font-family: 'Arial',sans-serif;\">The LXC utilities enable an administrator to modify a container\u2019s configuration file (located in \/var\/lib\/lxc), if it\u2019s necessary to configure one or more containers to take on a number of different tasks. This syntax will give access to the relevant configuration file:<\/span><\/p>\n<p style=\"margin: 0px; line-height: 150%;\"><span style=\"margin: 0px; font-family: 'Arial',sans-serif;\">\u00a0<\/span><\/p>\n<p style=\"margin: 0px; line-height: 150%;\"><span style=\"margin: 0px; font-family: 'Arial',sans-serif;\">$ sudo su<\/span><\/p>\n<p style=\"margin: 0px; line-height: 150%;\"><span style=\"margin: 0px; font-family: 'Arial',sans-serif;\"># cd \/var\/lib\/lxc<\/span><\/p>\n<p style=\"margin: 0px; line-height: 150%;\"><span style=\"margin: 0px; font-family: 'Arial',sans-serif;\"># ls<\/span><\/p>\n<p style=\"margin: 0px; line-height: 150%;\"><span style=\"margin: 0px; font-family: 'Arial',sans-serif;\">example-container <\/span><\/p>\n<p style=\"margin: 0px; line-height: 150%;\"><span style=\"margin: 0px; font-family: 'Arial',sans-serif;\">\u00a0<\/span><\/p>\n<h2 style=\"margin: 13.33px 0px 0px;\"><span style=\"margin: 0px; font-family: 'Arial',sans-serif;\">Balancing Privileged and Unprivileged Containers<\/span><\/h2>\n<p style=\"margin: 0px; line-height: 150%;\"><span style=\"margin: 0px; font-family: 'Arial',sans-serif;\">\u00a0<\/span><\/p>\n<p style=\"margin: 0px; line-height: 150%;\"><span style=\"margin: 0px; font-family: 'Arial',sans-serif;\">Unprivileged containers run with a mapping of the container\u2019s root UID to a non-root UID on the host system. This adds a layer of security which makes it harder for an attacker to compromise the container and gain root privileges to the underlying host machine.<\/span><\/p>\n<p style=\"margin: 0px; line-height: 150%;\"><span style=\"margin: 0px; font-family: 'Arial',sans-serif;\">\u00a0<\/span><\/p>\n<p style=\"margin: 0px; line-height: 150%;\"><span style=\"margin: 0px; font-family: 'Arial',sans-serif;\">Privileged containers don\u2019t provide this level of segregation from the host and can potentially leave a system vulnerable. So it\u2019s a good idea to minimize their use as much as possible.<\/span><\/p>\n<p style=\"margin: 0px; line-height: 150%;\"><span style=\"margin: 0px; font-family: 'Arial',sans-serif;\">\u00a0<\/span><\/p>\n<h2 style=\"margin: 13.33px 0px 0px;\"><span style=\"margin: 0px; font-family: 'Arial',sans-serif;\">Choosing Between LXC and Docker<\/span><\/h2>\n<p style=\"margin: 0px; line-height: 150%;\"><span style=\"margin: 0px; font-family: 'Arial',sans-serif;\">\u00a0<\/span><\/p>\n<p style=\"margin: 0px; line-height: 150%;\"><span style=\"margin: 0px; font-family: 'Arial',sans-serif;\">We\u2019ve spoken a lot about the LXC utilities, which are the \u201cnative\u201d <span style=\"margin: 0px;\"><a href=\"https:\/\/www.redhat.com\/en\/topics\/containers\/whats-a-linux-container\" rel=\"nofollow\" target=\"_blank\">Linux solution for container management<img class=\"extlink-icon\" src=\"https:\/\/www.poweradmin.com\/blog\/wp-content\/plugins\/external-links-nofollow-open-in-new-tab-favicon\/images\/extlink.png\"><\/a><\/span>. But a proprietary management system known as Docker also exists, which has been licensed by Apache as an open-source containerization solution for automating the tasks of creating and deploying micro-services inside containers. <\/span><\/p>\n<p style=\"margin: 0px; line-height: 150%;\"><span style=\"margin: 0px; font-family: 'Arial',sans-serif;\">\u00a0<\/span><\/p>\n<p style=\"margin: 0px; line-height: 150%;\"><span style=\"margin: 0px; font-family: 'Arial',sans-serif;\">Docker uses the kernel cgroup subsystem and takes an image-based approach in treating containers like extremely lightweight and modular virtual machines. Portability and rapid deployment are its main strengths, enhanced by the ability to easily roll back an image layer to its previous version.<\/span><\/p>\n<p style=\"margin: 0px; line-height: 150%;\"><span style=\"margin: 0px; font-family: 'Arial',sans-serif;\">\u00a0<\/span><\/p>\n<p style=\"margin: 0px; line-height: 150%;\"><span style=\"margin: 0px; font-family: 'Arial',sans-serif;\">However, Docker restricts containers to run as a single process and doesn\u2019t support persistent storage. <\/span><\/p>\n<p style=\"margin: 0px; line-height: 150%;\"><span style=\"margin: 0px; font-family: 'Arial',sans-serif;\">\u00a0<\/span><\/p>\n<p style=\"margin: 0px; line-height: 150%;\"><span style=\"margin: 0px; font-family: 'Arial',sans-serif;\">Ultimately, the choice of which container management option (or combination of tools) to use will be determined by the operational and administrative demands of your Linux environment.<\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>By Des Nnochiri \u00a0 Within a Linux network or development system, launching a limited set of applications or services (often known as microservices) in a self-sustaining container or sandboxed environment is sometimes necessary. A container enables administrators to decouple a specific set of software applications from the operating system and have them run within a [&hellip;]<\/p>\n","protected":false},"author":15,"featured_media":6295,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4,5,447,9],"tags":[192,464,291,465,458,450,456,457,463,468,455,398,421,451,448,454,459,420,461,449,188,466,452,453,460,64,462,467],"class_list":["post-6260","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-general-it","category-how-to","category-linux","category-technical","tag-access","tag-access-rights","tag-authorization","tag-authorized-users","tag-cgroups","tag-container","tag-container-isolation","tag-control-groups","tag-debian","tag-docker","tag-isolation","tag-linux","tag-linux-configuration","tag-linux-containers","tag-linux-development-system","tag-linux-isolation","tag-linux-kernel","tag-linux-network","tag-lxc","tag-microservice","tag-network","tag-privileged-containers","tag-rpm","tag-rpm-package","tag-systemd","tag-troubleshooting","tag-ubuntu","tag-unprivileged-containers"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.poweradmin.com\/blog\/wp-json\/wp\/v2\/posts\/6260","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.poweradmin.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.poweradmin.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.poweradmin.com\/blog\/wp-json\/wp\/v2\/users\/15"}],"replies":[{"embeddable":true,"href":"https:\/\/www.poweradmin.com\/blog\/wp-json\/wp\/v2\/comments?post=6260"}],"version-history":[{"count":5,"href":"https:\/\/www.poweradmin.com\/blog\/wp-json\/wp\/v2\/posts\/6260\/revisions"}],"predecessor-version":[{"id":6279,"href":"https:\/\/www.poweradmin.com\/blog\/wp-json\/wp\/v2\/posts\/6260\/revisions\/6279"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.poweradmin.com\/blog\/wp-json\/wp\/v2\/media\/6295"}],"wp:attachment":[{"href":"https:\/\/www.poweradmin.com\/blog\/wp-json\/wp\/v2\/media?parent=6260"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.poweradmin.com\/blog\/wp-json\/wp\/v2\/categories?post=6260"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.poweradmin.com\/blog\/wp-json\/wp\/v2\/tags?post=6260"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}