{"id":1942,"date":"2019-03-01T13:51:54","date_gmt":"2019-03-01T12:51:54","guid":{"rendered":"https:\/\/solidt.eu\/site\/?p=1942"},"modified":"2021-03-11T23:26:45","modified_gmt":"2021-03-11T22:26:45","slug":"linux-lxd-lxc-containers","status":"publish","type":"post","link":"https:\/\/solidt.eu\/site\/linux-lxd-lxc-containers\/","title":{"rendered":"Linux: LXD \/LXC containers"},"content":{"rendered":"\n<p>Source: <a href=\"https:\/\/gist.github.com\/berndbausch\/a6835150c7a26c88048763c0bd739be6\">https:\/\/gist.github.com\/berndbausch\/a6835150c7a26c88048763c0bd739be6<\/a><\/p>\n\n\n\n<p>Interestingly, the LXD command line client is named&#8230;.&nbsp;<code>lxc<\/code>!<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><a href=\"https:\/\/gist.github.com\/berndbausch\/a6835150c7a26c88048763c0bd739be6#list-available-containers\"><\/a>List available containers<\/h3>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">lxc image list ubuntu:        # ubuntu: is officially supported image source\nlxc image list images:        # images: is an unsupported source\nlxc image alias list images:  # lists user-friendly names\n<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\"><a href=\"https:\/\/gist.github.com\/berndbausch\/a6835150c7a26c88048763c0bd739be6#launch-a-container\"><\/a>Launch a container<\/h3>\n\n\n\n<p>This creates and starts a container.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">lxc launch ubuntu:14.04 CONTAINERNAME \u00a0 # image and container names are optional \nlxc launch ubuntu:14.04\/armhf armcont \u00a0 # specific architecture\nlxc launch images:alpine\/3.3\/amd64      # unsupported images: source\n<\/pre>\n\n\n\n<h4 class=\"wp-block-heading\"><a href=\"https:\/\/gist.github.com\/berndbausch\/a6835150c7a26c88048763c0bd739be6#create-container\"><\/a>Create container<\/h4>\n\n\n\n<p>Without starting it.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">lxc init images:alpine\/3.3\/amd64 alpinecont\nlxc copy CONTAINER1 CONTAINER2        # clone\nlxc delete alpinecont [--force]       # --force if it is running\n<\/pre>\n\n\n\n<h4 class=\"wp-block-heading\"><a href=\"https:\/\/gist.github.com\/berndbausch\/a6835150c7a26c88048763c0bd739be6#startstop-after-creating-it\"><\/a>Start\/stop after creating it<\/h4>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">lxc start alpinecont\nlxc stop alpinecont [--force]         # --force if it doesn't want to stop\nlxc restart alpinecont [--force]\nlxc pause alpinecont                  # SIGSTOP to all container processes\n<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\"><a href=\"https:\/\/gist.github.com\/berndbausch\/a6835150c7a26c88048763c0bd739be6#list-local-containers\"><\/a>List local containers<\/h3>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">lxc list \nlxc list --columns \"nsapt\"            # name, status, arch, PID of init, type\nlxc list security.privileged=true     # filter for properties\nlxc info CONTAINERNAME                # detailed info about one container\n<\/pre>\n\n\n\n<h4 class=\"wp-block-heading\"><a href=\"https:\/\/gist.github.com\/berndbausch\/a6835150c7a26c88048763c0bd739be6#available-columns-for-the-list-command\"><\/a>Available columns for the list command<\/h4>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">    4 - IPv4 address\n    6 - IPv6 address\n    a - Architecture\n    c - Creation date\n    n - Name\n    p - PID of the container's init process\n    P - Profiles\n    s - State\n    S - Number of snapshots\n    t - Type (persistent or ephemeral)\n<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\"><a href=\"https:\/\/gist.github.com\/berndbausch\/a6835150c7a26c88048763c0bd739be6#rename\"><\/a>Rename<\/h3>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">lxc move CONTAINERNAME NEWNAME\n<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\"><a href=\"https:\/\/gist.github.com\/berndbausch\/a6835150c7a26c88048763c0bd739be6#configuration\"><\/a>Configuration<\/h3>\n\n\n\n<p>Config changes are effective immediately, even if container is running.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">export VISUAL=\/usr\/bin\/vim\nlxc config edit CONTAINERNAME           # launches editor\nlxc config set CONTAINERNAME KEY VALUE  # change a single config item\nlxc config device add CONTAINERNAME DEVICE TYPE KEY=VALUE\nlxc config show [--expanded] CONTAINERNAME\nConfiguration settings can be saved as **profiles**.\n<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\"><a href=\"https:\/\/gist.github.com\/berndbausch\/a6835150c7a26c88048763c0bd739be6#enter-the-container\"><\/a>Enter the container<\/h3>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">lxc exec CONTAINERNAME -- PROGRAM OPTIONS\nlxc exec CONTAINERNAME sh\nlxc exec CONATINERNAME --env KEY=VALUE PROGRAM   # environment variable\n<\/pre>\n\n\n\n<p>This command runs the program in all the namespaces and cgroups of the container. The program must exist inside the container.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><a href=\"https:\/\/gist.github.com\/berndbausch\/a6835150c7a26c88048763c0bd739be6#access-container-files\"><\/a>Access container files<\/h3>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">lxc file pull CONTAINERNAME\/etc\/passwd \/tmp\/mypasswd\nlxc file push \/tmp\/mypasswd CONTAINERNAME\/etc\/passwd \nlxc file edit CONTAINERNAME\/etc\/passwd \n<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\"><a href=\"https:\/\/gist.github.com\/berndbausch\/a6835150c7a26c88048763c0bd739be6#snapshots\"><\/a>Snapshots<\/h3>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">lxc snapshot CONTAINERNAME SNAPNAME    # SNAPNAME is optional; default name snap*X*\nlxc restore CONTAINERNAME SNAPNAME     # resets the container to snapshot\nlxc copy CONTAINERNAME\/SNAPNAME NEWCONTAINER               # new container from snapshot\nlxc delete CONTAINERNAME\/SNAPNAME\nlxc info CONTAINERNAME                 # lists snapshots among other info\nlxc move CONTAINERNAME\/SNAPNAME CONTAINERNAME\/NEWSNAPNAME  # rename snapshot<\/pre>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"shell\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\"># Forward a local port to a container\nlxc config device add nx-mysql-1 myport3306 proxy listen=tcp:0.0.0.0:3306 connect=tcp:127.0.0.1:3306\n\n# Update a (ubuntu\/mint) container\nlxc exec $container -- bash -c \"apt update &amp;&amp; apt upgrade -y &amp;&amp; apt autoremove -y\"\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Source: https:\/\/gist.github.com\/berndbausch\/a6835150c7a26c88048763c0bd739be6 Interestingly, the LXD command line client is named&#8230;.&nbsp;lxc! List available containers Launch a container This creates and starts a container. Create container Without starting it. Start\/stop after creating it List local containers Available columns for the list command Rename Configuration Config changes are effective immediately, even if container is running. Enter the container [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"inline_featured_image":false,"footnotes":""},"categories":[1],"tags":[],"class_list":["post-1942","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/solidt.eu\/site\/wp-json\/wp\/v2\/posts\/1942","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/solidt.eu\/site\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/solidt.eu\/site\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/solidt.eu\/site\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/solidt.eu\/site\/wp-json\/wp\/v2\/comments?post=1942"}],"version-history":[{"count":5,"href":"https:\/\/solidt.eu\/site\/wp-json\/wp\/v2\/posts\/1942\/revisions"}],"predecessor-version":[{"id":4704,"href":"https:\/\/solidt.eu\/site\/wp-json\/wp\/v2\/posts\/1942\/revisions\/4704"}],"wp:attachment":[{"href":"https:\/\/solidt.eu\/site\/wp-json\/wp\/v2\/media?parent=1942"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/solidt.eu\/site\/wp-json\/wp\/v2\/categories?post=1942"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/solidt.eu\/site\/wp-json\/wp\/v2\/tags?post=1942"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}