LoginSignup
3
2

More than 5 years have passed since last update.

LXD 2.0: LXDの中でLXD [8/12]

Last updated at Posted at 2016-04-17

この文書について

この文書は、連載記事「LXD 2.0: Blog post series」(日本語版目次)の一つである以下の記事を翻訳したものです。

この文書のライセンスは原文と同じく、Creative Commons BY-NC-SA 2.5のもとに提供されています。

CC-BY-NC-SA 2.5


はじめに

前の投稿ではLXDの中でDockerを動かす方法について説明しました。これはDockerが提供するアプリケーション一式を、LXD環境の中でより安全に実行する良い方法です。

LXDコンテナをユーザーに提供する一つの利用方法が、Dockerを実行できるコンテナを提供することでした。また、ユーザー自身がLXDを用いてコンテナの中で何か別のLinuxディストリビューションを動かしたい場合があるかもしれませんし、何か別のグループに彼らが動かしているコンテナ内のLinuxシステムへのアクセスを許可したい場合があるかもしれません。

まとめると、LXDはとても簡単にコンテナのネストが可能です。

LXDのネスト

もっとも単純な例はUbuntu 16.04イメージを使うことです。Ubuntu 16.04のクラウドイメージは最初からLXDがインストールされています。デーモン自身は何かソケットを有効化して動いているわけではなく、ユーザーが通信を開始するまでは何もリソースを消費しません。

さて、ネストを有効にした上でUbuntu 16.04コンテナを起動してみましょう:

lxc launch ubuntu-daily:16.04 c1 -c security.nesting=true

既存のコンテナに対してsecurity.nesting設定を変更することも可能です:

lxc config set コンテナ名 security.nesting true

特定のプロファイルを適用しているコンテナすべてに反映したい場合は、次のように設定します:

lxc profile set プロファイル名 security.nesting true

コンテナを起動したら、その中でシェルを実行し、LXDを設定した上で、さらにコンテナを起動できます:

stgraber@dakara:~$ lxc launch ubuntu-daily:16.04 c1 -c security.nesting=true
Creating c1
Starting c1

stgraber@dakara:~$ lxc exec c1 bash
root@c1:~# lxd init
Name of the storage backend to use (dir or zfs): 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)? yes
Would you like LXD to be available over the network (yes/no)? no
Do you want to configure the LXD bridge (yes/no)? yes
Warning: Stopping lxd.service, but it can still be activated by:
 lxd.socket
LXD has been successfully configured.

root@c1:~# lxc launch ubuntu:14.04 trusty
Generating a client certificate. This may take a minute...
If this is your first time using LXD, you should also run: sudo lxd init

Creating trusty
Retrieving image: 100%
Starting trusty

root@c1:~# lxc list
+--------+---------+-----------------------+----------------------------------------------+------------+-----------+
|  NAME  |  STATE  |         IPV4          |                     IPV6                     |    TYPE    | SNAPSHOTS |
+--------+---------+-----------------------+----------------------------------------------+------------+-----------+
| trusty | RUNNING | 10.153.141.124 (eth0) | fd7:f15d:d1d6:da14:216:3eff:fef1:4002 (eth0) | PERSISTENT | 0         |
+--------+---------+-----------------------+----------------------------------------------+------------+-----------+
root@c1:~#

とても簡単ですね!

オンラインのデモサーバー

この投稿はとても短くなってしまったので、デモサーバーについても説明しておきましょう。本日未明には10000セッションに到達しました!

サーバーは基本的に、それなりにリッチな仮想マシンの中で通常のLXDデーモンと、ウェブサイトから使うREST APIを実装た小さなデーモンを動かしています。

利用規約に同意すれば、上記で説明したようにsecurity.nestingが有効化された新しいLXDコンテナが起動します。その後「lxc exec」を実行した時と同じようなアタチで作られたコンテナの中に入ります。ただしこれはWeb SocketとJavaScriptで実現しています。

この環境の中で作成したコンテナはすべて、ネストされたLXDコンテナです。必要であれば、さらに深いネストを構築することも可能です。

LXDによるリソース制限を用いて、あるユーザーの操作が他のユーザーに影響を与えないようにし、そのような兆候を把握すべくモニタリングを行っています。

同様のサーバーを作りたい場合は、ウェブサイトとデーモンのコードを取得して実行できます:

git clone github.com/lxc/linuxcontainers.org
git clone github.com/lxc/lxd-demo-server

その他の情報

3
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
2