当前位置: 首页 > 科技观察

LXD2.0系列(八):LXD中的LXD

时间:2023-03-13 02:53:39 科技观察

这是LXD2.0系列介绍文章的第八篇。GettingStartedwithLXDInstallingandConfiguringYourFirstLXDContainerResourceControlImageManagementRemoteHostandContainerMigrationLXD中的Docker简介在上一篇文章中,我介绍了如何在LXD中运行Docker,这是一种提供应用程序组合的好方法,而Docker也运行在LXD提供的安全环境中。我提到的一个场景是为您的用户提供一个LXD容器,然后让他们使用他们的容器来运行Docker。那么如果他们自己想在他们的容器中使用LXD来运行其他Linux发行版,甚至允许另一群人访问他们容器中运行的Linux系统怎么办?事实证明,LXD使用户运行嵌套容器变得非常容易。简单的。可以使用Ubuntu16.04映像演示嵌套LXD的最简单情况。Ubuntu16.04云镜像预装了LXD。守护进程本身并没有运行,因为它是套接字激活的,所以在您实际使用它之前它不会使用任何资源。让我们启动一个启用嵌套的Ubuntu16.04容器:lxclaunchubuntu-daily:16.04c1-csecurity.nesting=true您还可以在现有容器上设置security.nesting:lxcconfigsetsecurity.nestingtrue或为所有容器使用指定的配置文件:lxcprofilesetsecurity.nestingtrue容器启动后,可以从容器内部获取shell,配置LXD并生成容器:stgraber@dakara:~$lxclaunchubuntu-daily:16.04c1-csecurity.nesting=trueCreatingc1Startingc1stgraber@dakara:~$lxcexecc1bashroot@c1:~#lxdinitNameofthestoragebackendtouse(dirorzfs):dirWedetectedthatyouarerunninginsideanunprivilegedcontainer.Thismeansthatunlessyoumanuallyconfiguredyourhostotherwise,youwillnothaveenoughuidandgidtoallocatetoyourcontainers.LXDcanre-useyourcontainer'sownallocationtoavoidtheproblem.Doingsomakesyournestedcontainersslightlylesssafeastheycouldintheoryattacktheirparentcontainerandgainmoreprivilegesthantheyotherwisewould.Wouldyouliketohave您的容器共享其父容器的分配(是/否)?是您是否希望LXD通过网络可用(是/否)?不你要吗toconfiguretheLXDbridge(yes/no)?yesWarning:Stoppinglxd.service,butitcanstillbeactivatedby:lxd.socketLXDhasbeensuccessfullyconfigured.root@c1:~#lxclaunchubuntu:14.04trustyGeneratingaclientcertificate.Thismaytakeaminute...IfthisisyourfirsttimeusingLXD,youshouldalsorun:sudolxdinitCreatingtrustyRetrievingimage:100%Startingtrustyroot@c1:~#lxclist+-------+--------+--------------------+--------------------------------------------+-------------+----------+|名称|状态|IPV4|IPV6|类型|快照|+--------+--------+--------------------+---------------------------------------------+------------+------------+|trusty|RUNNING|10.153。141.124(eth0)|fd7:f15d:d1d6:da14:216:3eff:fef1:4002(eth0)|PERSISTENT|0|+--------+--------+---------------------+-------------------------------------------+------------+------------+root@c1:~#就是这样it简单的在线演示服务器由于这篇文章很短,我想我应该花点时间谈谈我们的演示服务器。我们今天早些时候刚刚达到10,000次会话!服务器基本上只是一个运行在相当强大的虚拟机上的普通LXD,一个实现我们网站使用的RESTAPI的小型守护进程。当您接受服务条款时,将为您创建一个新的LXD容器,并如上所述启用security.nesting。然后你像使用lxcexec一样连接到那个容器,除了我们使用websockets和javascript来做到这一点。您在此环境中创建的容器都是嵌套的LXD容器。如果你愿意,你可以进一步嵌套。我们全面使用LXD资源限制来防止一个用户的行为影响其他用户,并仔细监控服务器是否有任何滥用迹象。如果您想运行自己的类似服务器,可以获取我们的网站和守护程序的代码:gitclonehttps://github.com/lxc/linuxcontainers.orggitclonehttps://github.com/lxc/lxd-demo-server信息LXD的主要网站:https://linuxcontainers.org/lxdLXD的GitHub存储库:https://github.com/lxc/lxdLXD的邮件列表:https://lists.linuxcontainers.orgLXD的IRC频道:irc.freenode上的#lxcontainers。网