溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊(cè)×
其他方式登錄
點(diǎn)擊 登錄注冊(cè) 即表示同意《億速云用戶(hù)服務(wù)條款》

怎么在LXD容器中運(yùn)行Ubuntu Core

發(fā)布時(shí)間:2022-01-27 09:19:37 來(lái)源:億速云 閱讀:118 作者:iii 欄目:開(kāi)發(fā)技術(shù)

本篇內(nèi)容主要講解“怎么在LXD容器中運(yùn)行Ubuntu Core”,感興趣的朋友不妨來(lái)看看。本文介紹的方法操作簡(jiǎn)單快捷,實(shí)用性強(qiáng)。下面就讓小編來(lái)帶大家學(xué)習(xí)“怎么在LXD容器中運(yùn)行Ubuntu Core”吧!

LXD 就是一個(gè)提供了 REST API 的 LXC 容器管理器,LXD 最主要的目標(biāo)就是使用 Linux 容器而不是硬件虛擬化向用戶(hù)提供一種接近虛擬機(jī)的使用體驗(yàn)。

怎么在LXD容器中運(yùn)行Ubuntu Core

環(huán)境需求

就 LXD 而言,Ubuntu Core 僅僅相當(dāng)于另一個(gè) Linux 發(fā)行版。也就是說(shuō),snapd 需要掛載無(wú)特權(quán)的 FUSE 和 AppArmor 命名空間以及軟件棧,像下面這樣:

  1. 一個(gè)新版的使用 Ubuntu 官方內(nèi)核的系統(tǒng)
  2. 一個(gè)新版的 LXD

創(chuàng)建一個(gè) Ubuntu Core 容器

當(dāng)前 Ubuntu Core 鏡像發(fā)布在社區(qū)的鏡像服務(wù)器。你可以像這樣啟動(dòng)一個(gè)新的容器:

stgraber@dakara:~$ lxc launch images:ubuntu-core/16 ubuntu-core
Creating ubuntu-core
Starting ubuntu-core

這個(gè)容器啟動(dòng)需要一點(diǎn)點(diǎn)時(shí)間,它會(huì)先執(zhí)行第一階段的加載程序,加載程序會(huì)確定使用哪一個(gè)鏡像(鏡像是只讀的),并且在系統(tǒng)上設(shè)置一個(gè)可讀層,你不要在這一階段中斷容器執(zhí)行,這個(gè)時(shí)候什么都沒(méi)有,所以執(zhí)行l(wèi)xc exec 將會(huì)出錯(cuò)。

幾秒鐘之后,執(zhí)行 lxc list 將會(huì)展示容器的 IP 地址,這表明已經(jīng)啟動(dòng)了 Ubuntu Core:

stgraber@dakara:~$ lxc list
+-------------+---------+----------------------+----------------------------------------------+------------+-----------+
|     NAME    |  STATE  |          IPV4        |                      IPV6                    |    TYPE    | SNAPSHOTS |
+-------------+---------+----------------------+----------------------------------------------+------------+-----------+
| ubuntu-core | RUNNING | 10.90.151.104 (eth0) | 2001:470:b368:b2b5:216:3eff:fee1:296f (eth0) | PERSISTENT | 0         |
+-------------+---------+----------------------+----------------------------------------------+------------+-----------+

之后你就可以像使用其他的交互一樣和這個(gè)容器進(jìn)行交互:

stgraber@dakara:~$ lxc exec ubuntu-core bash
root@ubuntu-core:~# snap listName       Version     Rev  Developer  Notes
core       16.04.1     394  canonical  -
pc         16.04-0.8   9    canonical  -
pc-kernel  4.4.0-45-4  37   canonical  -
root@ubuntu-core:~#

更新容器

如果你一直關(guān)注著 Ubuntu Core 的開(kāi)發(fā),你應(yīng)該知道上面的版本已經(jīng)很老了。這是因?yàn)楸挥米?Ubuntu LXD 鏡像的代碼每隔幾個(gè)月才會(huì)更新。Ubuntu Core 系統(tǒng)在重啟時(shí)會(huì)檢查更新并進(jìn)行自動(dòng)更新(更新失敗會(huì)回退)。

如果你想現(xiàn)在強(qiáng)制更新,你可以這樣做:

stgraber@dakara:~$ lxc exec ubuntu-core bash
root@ubuntu-core:~# snap refreshpc-kernel (stable) 4.4.0-53-1 from 'canonical' upgraded
core (stable) 16.04.1 from 'canonical' upgraded
root@ubuntu-core:~# snap versionsnap 2.17
snapd 2.17
series 16
root@ubuntu-core:~#然后重啟一下 Ubuntu Core 系統(tǒng),然后看看 snapd 的版本。
root@ubuntu-core:~# rebootroot@ubuntu-core:~#stgraber@dakara:~$ lxc exec ubuntu-core bash
root@ubuntu-core:~# snap versionsnap 2.21
snapd 2.21
series 16
root@ubuntu-core:~#

你也可以像下面這樣查看所有 snapd 的歷史記錄:

stgraber@dakara:~$ lxc exec ubuntu-core snap changes
ID  Status  Spawn                 Ready                 Summary
1   Done    2017-01-31T05:14:38Z  2017-01-31T05:14:44Z  Initialize system state
2   Done    2017-01-31T05:14:40Z  2017-01-31T05:14:45Z  Initialize device
3   Done    2017-01-31T05:21:30Z  2017-01-31T05:22:45Z  Refresh all snaps in the system

安裝 Snap 軟件包

以一個(gè)最簡(jiǎn)單的例子開(kāi)始,經(jīng)典的 Hello World:

stgraber@dakara:~$ lxc exec ubuntu-core bash
root@ubuntu-core:~# snap install hello-worldhello-world 6.3 from 'canonical' installed
root@ubuntu-core:~# hello-worldHello World!

接下來(lái)讓我們看一些更有用的:

stgraber@dakara:~$ lxc exec ubuntu-core bash
root@ubuntu-core:~# snap install nextcloudnextcloud 11.0.1snap2 from 'nextcloud' installed

之后通過(guò) HTTP 訪(fǎng)問(wèn)你的容器就可以看到剛才部署的 Nextcloud 實(shí)例。

如果你想直接通過(guò) git 測(cè)試最新版 LXD,你可以這樣做:

stgraber@dakara:~$ lxc config set ubuntu-core security.nesting truestgraber@dakara:~$ lxc exec ubuntu-core bash
root@ubuntu-core:~# snap install lxd --edgelxd (edge) git-c6006fb from 'canonical' installed
root@ubuntu-core:~# lxd initName of the storage backend to use (dir or zfs) [default=dir]:
We detected that you are running inside an unprivileged container.
This means that unless you manually configured your host otherwise,
you will not have enough uid and gid to allocate to your containers.
LXD can re-use your container's own allocation to avoid the problem.
Doing so makes your nested containers slightly less safe as they could
in theory attack their parent container and gain more privileges than
they otherwise would.
Would you like to have your containers share their parent's allocation (yes/no) [default=yes]?
Would you like LXD to be available over the network (yes/no) [default=no]?
Would you like stale cached images to be updated automatically (yes/no) [default=yes]?
Would you like to create a new network bridge (yes/no) [default=yes]?
What should the new bridge be called [default=lxdbr0]?
What IPv4 address should be used (CIDR subnet notation, “auto” or “none”) [default=auto]?
What IPv6 address should be used (CIDR subnet notation, “auto” or “none”) [default=auto]?
LXD has been successfully configured.

已經(jīng)設(shè)置過(guò)的容器不能回退版本,但是可以在 Ubuntu Core 16 中運(yùn)行另一個(gè) Ubuntu Core 16 容器:

root@ubuntu-core:~# lxc launch images:ubuntu-core/16 nested-coreCreating nested-core
Starting nested-core
root@ubuntu-core:~# lxc list+-------------+---------+---------------------+-----------------------------------------------+------------+-----------+
|    NAME     |  STATE  |         IPV4        |                       IPV6                    |    TYPE    | SNAPSHOTS |
+-------------+---------+---------------------+-----------------------------------------------+------------+-----------+
| nested-core | RUNNING | 10.71.135.21 (eth0) | fd42:2861:5aad:3842:216:3eff:feaf:e6bd (eth0) | PERSISTENT | 0         |
+-------------+---------+---------------------+-----------------------------------------------+------------+-----------+

到此,相信大家對(duì)“怎么在LXD容器中運(yùn)行Ubuntu Core”有了更深的了解,不妨來(lái)實(shí)際操作一番吧!這里是億速云網(wǎng)站,更多相關(guān)內(nèi)容可以進(jìn)入相關(guān)頻道進(jìn)行查詢(xún),關(guān)注我們,繼續(xù)學(xué)習(xí)!

向AI問(wèn)一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀(guān)點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI