自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

LXD 2.0 系列(七):LXD中的Docker

系統(tǒng) Linux
這是 LXD 2.0 系列介紹文章的第七篇。使用 Ubuntu 16.04 和 LXD 2.0,您可以為用戶創(chuàng)建容器,然后可以像正常的 Ubuntu 系統(tǒng)一樣連接到這些容器,然后運行 Docker 來安裝他們想要的服務和應用程序。

[[184291]]

這是 LXD 2.0 系列介紹文章的第七篇。

  1. LXD 入門
  2. 安裝與配置
  3. 你的第一個 LXD 容器
  4. 資源控制
  5. 鏡像管理
  6. 遠程主機及容器遷移

為什么在 LXD 中運行 Docker

正如我在系列的第一篇中簡要介紹的,LXD 的重點是系統(tǒng)容器,也就是我們在容器中運行一個完全未經修改的 Linux 發(fā)行版。LXD 的所有意圖和目的并不在乎容器中的負載是什么。它只是設置容器命名空間和安全策略,然后運行 /sbin/init 來生成容器,接著等待容器停止。

應用程序容器,例如由 Docker 或 Rkt 所實現(xiàn)的應用程序容器是非常不同的,因為它們用于分發(fā)應用程序,通常在它們內部運行單個主進程,并且比 LXD 容器生命期更短暫。

這兩種容器類型不是相互排斥的,我們的確看到使用 Docker 容器來分發(fā)應用程序的價值。這就是為什么我們在過去一年中努力工作以便讓 LXD 中運行 Docker 成為可能。

這意味著,使用 Ubuntu 16.04 和 LXD 2.0,您可以為用戶創(chuàng)建容器,然后可以像正常的 Ubuntu 系統(tǒng)一樣連接到這些容器,然后運行 Docker 來安裝他們想要的服務和應用程序。

要求

要讓它正常工作要做很多事情,Ubuntu 16.04 上已經包含了這些:

  • 支持 CGroup 命名空間的內核(4.4 Ubuntu 或 4.6 主線內核)
  • 使用 LXC 2.0 和 LXCFS 2.0 的 LXD 2.0
  • 一個自定義版本的 Docker(或一個用我們提交的所有補丁構建的)
  • Docker 鏡像,其受限于用戶命名空間限制,或者使父 LXD 容器成為特權容器(security.privileged = true)

運行一個基礎的 Docker 載荷

說完這些,讓我們開始運行 Docker 容器!

首先你可以用下面的命令得到一個 Ubuntu 16.04 的容器:

  1. lxc launch ubuntu-daily:16.04 docker -p default -p docker 

-p default -p docker 表示 LXD 將 default 和 docker 配置文件應用于容器。default 配置文件包含基本網絡配置,而 docker 配置文件告訴 LXD 加載幾個必需的內核模塊并為容器設置一些掛載。 docker 配置文件還支持容器嵌套。

現(xiàn)在讓我們確保容器是最新的并安裝 docker:

  1. lxc exec docker -- apt update 
  2. lxc exec docker -- apt dist-upgrade -y 
  3. lxc exec docker -- apt install docker.io -y 

就是這樣!你已經安裝并運行了一個 Docker 容器。

現(xiàn)在讓我們用兩個 Docker 容器開啟一個基礎的 web 服務:

  1. stgraber@dakara:~$ lxc exec docker -- docker run --detach --name app carinamarina/hello-world-app 
  2. Unable to find image 'carinamarina/hello-world-app:latest' locally 
  3. latest: Pulling from carinamarina/hello-world-app 
  4. efd26ecc9548: Pull complete  
  5. a3ed95caeb02: Pull complete  
  6. d1784d73276e: Pull complete  
  7. 72e581645fc3: Pull complete  
  8. 9709ddcc4d24: Pull complete  
  9. 2d600f0ec235: Pull complete  
  10. c4cf94f61cbd: Pull complete  
  11. c40f2ab60404: Pull complete  
  12. e87185df6de7: Pull complete  
  13. 62a11c66eb65: Pull complete  
  14. 4c5eea9f676d: Pull complete  
  15. 498df6a0d074: Pull complete  
  16. Digest: sha256:6a159db50cb9c0fbe127fb038ed5a33bb5a443fcdd925ec74bf578142718f516 
  17. Status: Downloaded newer image for carinamarina/hello-world-app:latest 
  18. c8318f0401fb1e119e6c5bb23d1e706e8ca080f8e44b42613856ccd0bf8bfb0d 
  19. stgraber@dakara:~$ lxc exec docker -- docker run --detach --name web --link app:helloapp -p 80:5000 carinamarina/hello-world-web 
  20. Unable to find image 'carinamarina/hello-world-web:latest' locally 
  21. latest: Pulling from carinamarina/hello-world-web 
  22. efd26ecc9548: Already exists  
  23. a3ed95caeb02: Already exists  
  24. d1784d73276e: Already exists  
  25. 72e581645fc3: Already exists  
  26. 9709ddcc4d24: Already exists  
  27. 2d600f0ec235: Already exists  
  28. c4cf94f61cbd: Already exists  
  29. c40f2ab60404: Already exists  
  30. e87185df6de7: Already exists  
  31. f2d249ff479b: Pull complete  
  32. 97cb83fe7a9a: Pull complete  
  33. d7ce7c58a919: Pull complete  
  34. Digest: sha256:c31cf04b1ab6a0dac40d0c5e3e64864f4f2e0527a8ba602971dab5a977a74f20 
  35. Status: Downloaded newer image for carinamarina/hello-world-web:latest 
  36. d7b8963401482337329faf487d5274465536eebe76f5b33c89622b92477a670f 

現(xiàn)在這兩個 Docker 容器已經運行了,我們可以得到 LXD 容器的 IP 地址,并且訪問它的服務了!

  1. stgraber@dakara:~$ lxc list 
  2. +--------+---------+----------------------+----------------------------------------------+------------+-----------+ 
  3. |  NAME  |  STATE  |         IPV4         |                      IPV6                    |    TYPE    | SNAPSHOTS | 
  4. +--------+---------+----------------------+----------------------------------------------+------------+-----------+ 
  5. | docker | RUNNING | 172.17.0.1 (docker0) | 2001:470:b368:4242:216:3eff:fe55:45f4 (eth0) | PERSISTENT | 0         | 
  6. |        |         | 10.178.150.73 (eth0) |                                              |            |           | 
  7. +--------+---------+----------------------+----------------------------------------------+------------+-----------+ 
  8. stgraber@dakara:~$ curl http://10.178.150.73 
  9. The linked container said... "Hello World!" 

總結

就是這樣了!在 LXD 容器中運行 Docker 容器真的很簡單。

現(xiàn)在正如我前面提到的,并不是所有的 Docker 鏡像都會像我的示例一樣,這通常是因為 LXD 帶來了額外的限制,特別是用戶命名空間。

在這種模式下只有 Docker 的 overlayfs 存儲驅動可以工作。該存儲驅動有一組自己的限制,這進一步限制了在該環(huán)境中可以有多少鏡像工作。

如果您的負載無法正常工作,并且您信任該 LXD 容器中的用戶,你可以試下:

  1. lxc config set docker security.privileged true 
  2. lxc restart docker 

這將取消激活用戶命名空間,并以特權模式運行容器。

但是請注意,在這種模式下,容器內的 root 與主機上的 root 是相同的 uid。現(xiàn)在有許多已知的方法讓用戶脫離容器,并獲得主機上的 root 權限,所以你應該只有在信任你的 LXD 容器中的用戶可以具有主機上的 root 權限才這樣做。

額外信息

LXD 的主站在: https://linuxcontainers.org/lxd

LXD 的 GitHub 倉庫: https://github.com/lxc/lxd

LXD 的郵件列表: https://lists.linuxcontainers.org

LXD 的 IRC 頻道: #lxcontainers on irc.freenode.net

責任編輯:龐桂玉 來源: Linux中國
相關推薦

2017-03-06 14:00:22

LXD 2.0LXDLinux

2016-07-29 14:12:21

2017-03-08 18:00:10

LXD 2.0LinuxOpenStack

2017-03-08 10:40:14

LXD 2.0JujuLinux

2017-03-09 16:32:03

LXD 2.0Linux調試

2017-01-12 15:37:34

LinuxLXD 2.0鏡像管理

2016-12-29 11:01:03

LinuxLXD 2.0資源控制

2017-03-07 16:41:03

LXD 2.0Linux實時遷移

2016-08-24 15:12:41

LXDLinux容器

2016-08-22 21:41:37

LXDLinux容器管理器

2017-02-05 14:52:42

2015-04-24 10:57:22

Ubuntu 15.0Ubuntu

2014-11-20 10:12:59

Docker容器LXDCanonica

2017-12-25 13:51:32

LinuxUbuntu LinuLXD容器

2023-02-03 17:47:28

2023-01-13 16:34:08

2021-12-24 09:58:37

DockerMySQLLinux

2023-11-06 18:06:00

Docker容器

2021-06-11 07:49:01

Docker容器安全 應用程序

2022-11-19 09:30:31

開源容器
點贊
收藏

51CTO技術棧公眾號