您好,登錄后才能下訂單哦!
本篇內容主要講解“怎么在LXD容器中運行Ubuntu Core”,感興趣的朋友不妨來看看。本文介紹的方法操作簡單快捷,實用性強。下面就讓小編來帶大家學習“怎么在LXD容器中運行Ubuntu Core”吧!
LXD 就是一個提供了 REST API 的 LXC 容器管理器,LXD 最主要的目標就是使用 Linux 容器而不是硬件虛擬化向用戶提供一種接近虛擬機的使用體驗。
就 LXD 而言,Ubuntu Core 僅僅相當于另一個 Linux 發行版。也就是說,snapd 需要掛載無特權的 FUSE 和 AppArmor 命名空間以及軟件棧,像下面這樣:
當前 Ubuntu Core 鏡像發布在社區的鏡像服務器。你可以像這樣啟動一個新的容器:
stgraber@dakara:~$ lxc launch images:ubuntu-core/16 ubuntu-core Creating ubuntu-core Starting ubuntu-core
這個容器啟動需要一點點時間,它會先執行第一階段的加載程序,加載程序會確定使用哪一個鏡像(鏡像是只讀的),并且在系統上設置一個可讀層,你不要在這一階段中斷容器執行,這個時候什么都沒有,所以執行lxc exec 將會出錯。
幾秒鐘之后,執行 lxc list 將會展示容器的 IP 地址,這表明已經啟動了 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 | +-------------+---------+----------------------+----------------------------------------------+------------+-----------+
之后你就可以像使用其他的交互一樣和這個容器進行交互:
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:~#
如果你一直關注著 Ubuntu Core 的開發,你應該知道上面的版本已經很老了。這是因為被用作 Ubuntu LXD 鏡像的代碼每隔幾個月才會更新。Ubuntu Core 系統在重啟時會檢查更新并進行自動更新(更新失敗會回退)。
如果你想現在強制更新,你可以這樣做:
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 系統,然后看看 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
以一個最簡單的例子開始,經典的 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!
接下來讓我們看一些更有用的:
stgraber@dakara:~$ lxc exec ubuntu-core bash root@ubuntu-core:~# snap install nextcloudnextcloud 11.0.1snap2 from 'nextcloud' installed
之后通過 HTTP 訪問你的容器就可以看到剛才部署的 Nextcloud 實例。
如果你想直接通過 git 測試最新版 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.
已經設置過的容器不能回退版本,但是可以在 Ubuntu Core 16 中運行另一個 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 | +-------------+---------+---------------------+-----------------------------------------------+------------+-----------+
到此,相信大家對“怎么在LXD容器中運行Ubuntu Core”有了更深的了解,不妨來實際操作一番吧!這里是億速云網站,更多相關內容可以進入相關頻道進行查詢,關注我們,繼續學習!
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。