toto_1212

技術のログをツラツラ書きます。自分用ですが参考にしていただけたら嬉しいです。間違ってたらドンドン突っ込んでください。

【メモ】LXDを少し触ってみた

気になってたLXDを少し触ってみましたのでメモを残しておきます。

LXDって何? は以下を見てもらうと分かりやすいです。
Linux Containers - LXD - イントロダクション

まず、コンテナ上にOSを立ち上げるところを試してみました。

どんな環境でもいいのですが、Azure上にubuntuを立ち上げてその上でLXDを
動かしました。
#cat /etc/issue
Ubuntu 14.10 \n \l

リファレンスを見るとPPA を使うことを推奨しているようなので従います。

# add-apt-repository ppa:ubuntu-lxc/lxd-git-master
# apt-get update
# apt-get install lxd

次にイメージのインポートです。

ubuntu】
# lxd-images import lxc ubuntu testubuntu amd64 --alias ubuntu
【centos6】
# lxd-images import lxc centos 6 amd64 --alias centos6

落としたイメージを確認できます。

# lxc image list
 +---------+--------------+--------+-------------+--------+-------------------------------+
 |  ALIAS  | FINGERPRINT  | PUBLIC | DESCRIPTION |  ARCH  |          UPLOAD DATE          |
 +---------+--------------+--------+-------------+--------+-------------------------------+
 | ubuntu  | 04aac4257341 | no     |             | x86_64 | Jun 22, 2015 at 10:35am (UTC) |
 | centos6 | afae698680fc | no     |             | x86_64 | Jun 24, 2015 at 1:14am (UTC)  | 
 +---------+--------------+--------+-------------+--------+-------------------------------+

イメージから指定のOSでコンテナを起動する。

ロードしたいOSのALIASの名称をlaunchの後にいれ、コンテナ名(任意)を入力する
【ubuntu】
# lxc launch ubuntu testubuntu
【centos】
# lxc launch centos6 testcentos6

即立ち上がるので立ち上がったコンテナ一覧を出します。

# lxc list
 +-------------+---------+------------+------+-----------+-----------+
 |    NAME     |  STATE  |    IPV4    | IPV6 | EPHEMERAL | SNAPSHOTS | 
 +-------------+---------+------------+------+-----------+-----------+
 | testcentos6 | RUNNING | 10.0.3.194 |      | NO        | 0         |
 | testubuntu  | RUNNING | 10.0.3.107 |      | NO        | 0         |
 +-------------+---------+------------+------+-----------+-----------+

あとはコンテナに対し自由にコマンド入力できます。

# lxc exec testcentos6 -- uname -a
Linux testcentos6 3.16.0-39-generic #53-Ubuntu SMP Tue May 26 09:38:21 UTC 2015 x86_64 x86_64 x86_64 GNU/Linux

# lxc exec testcentos6 -- cat /etc/issue
CentOS release 6.6 (Final)
Kernel \r on an \m

# lxc exec testubuntu -- uname -a
Linux testubuntu 3.16.0-39-generic #53-Ubuntu SMP Tue May 26 09:38:21 UTC 2015 x86_64 x86_64 x86_64 GNU/Linux

# lxc exec testubuntu -- cat /etc/issue
Ubuntu 14.04.2 LTS \n \l

コンテナの内部でshellも打てます。

# lxc exec testcentos6 -- /bin/bash

[root@testcentos6 ~]# pstree
init-+-dhclient
     |-2*[mingetty]
     `-rsyslogd---2*[{rsyslogd}]

コンテナを停止させます。

# lxc stop testubuntu

# lxc list
 +-------------+---------+------------+------+-----------+-----------+
 |    NAME     |  STATE  |    IPV4    | IPV6 | EPHEMERAL | SNAPSHOTS |
 +-------------+---------+------------+------+-----------+-----------+
 | testcentos6 | RUNNING | 10.0.3.194 |      | NO        | 0         |
 | testubuntu  | STOPPED |            |      | NO        | 0         |
 +-------------+---------+------------+------+-----------+-----------+

停止したコンテナを起動させます。

# lxc start testubuntu

# lxc list
 +-------------+---------+------------+------+-----------+-----------+
 |    NAME     |  STATE  |    IPV4    | IPV6 | EPHEMERAL | SNAPSHOTS |
 +-------------+---------+------------+------+-----------+-----------+
 | testcentos6 | RUNNING | 10.0.3.194 |      | NO        | 0         |
 | testubuntu  | RUNNING | 10.0.3.107 |      | NO        | 0         |
 +-------------+---------+------------+------+-----------+-----------+

一連の流れは問題なくできそうです。
今のところ情報が少ないのでDocker(LXC)のほうが取っ付きやすい感じがしますが
もう少しLXDを追っかけてみようと思います。

ubuntuで有名な Canonical Ltd が商用盤として保守をされているようです。
www.canonical.com

LXDについて話されている動画もありました。
insights.ubuntu.com

参考Webサイト

[lxd] - TenForwardの日記

Ubuntu 15.04とLXDではじめるコンテナ型仮想化 | 株式会社インフィニットループ技術ブログ

lxc/lxd · GitHub