それマグで!

知識はカップより、マグでゆっくり頂きます。 takuya_1stのブログ

習慣に早くから配慮した者は、 おそらく人生の実りも大きい。

LXC のコマンドで基本操作 / lxc でイメージ検索とインストール / centosとubuntu

LXC のイメージについて。

LXDは仮想マシンの「統合管理」的なものなので 、docker のようなコンテナ、vbox のような仮想マシン、この2つを管理できる。コンテナは lxc のコンテナ、インスタンスqemu仮想マシンを扱えるようですね。

docker と違って lxc で起動すると、systemd がはじめから起動しているので、docker より扱いやすいです。

docker のようにストレージをレイヤ管理しないし、より「普通の仮想マシン」にちかいので、長期間運用するようなホストに向いていると思います。

「systemd が動いてる docker 」がほしいと思った方は lxc を選ぶと幸せになれるでしょう。

LXC のコマンド

LXC / lxd のコマンドは、現在は、lxc のコマンドとサブコマンドに統合されています。

lxc list 仮想マシン・コンテナの一覧

lxc list 

LXCで新規作成と終了と削除

新規作成

lxc launch ubuntu:18.04 myFirstContainer

このコマンドは、次のようになってる

lxc launch イメージ名 自分で決めるホスト名

停止・再起動・開始

lxc stop myFirstContainer
lxc restart myFirstContainer
lxc stop myFirstContainer

削除

削除は、停止後に出来ます。

lxc delete  myFirst

コンテナ環境内に入る

コンテナの中に入るには docker と変わりません。

lxc exec myFirst bash 

exec で任意のコマンドを実行できる。

lxc exec myFirst sh
lxc exec myFirst login
lxc exec myFirst systemctl status  sshd
lxc exec myFirst systemctl status nginx

イメージの検索について

LXDにビルトインされているイメージ用リモートサーバーの名前空間は、ubuntu のlxc では、次の3つです。

ubuntu:
ubunt-daily:
images:

取得済みのイメージ

lxc image list 

公式イメージ

取得済みのイメージと引数が違うだけなのでちょっと覚えづらい

lxc image list images:
lxc image list ubuntu:

イメージの一覧を見る時に使うコマンドの例

lxc image list images: 'debian'
lxc image list images: 'debian/11/amd64'
lxc image list images: 'centos'

検索イメージは多くなると 見づらいので grep するといい

lxc image  list  ubuntu: | grep 20.04
lxc image  list  images: | grep debian

さらに詳細を見たいときは次のようなオプションを使う

lxc image list images: 'debian/11/amd64' -c Lfpdatsu

イメージサーバーはどこにあるのかというと https://images.linuxcontainers.org/ をみると、全部見ることができるけど多すぎて見ることはないんじゃないかと。

debian を起動する場合

lxc image list images: debian

新規で起動するなら次のようにする

lxc launch images:debian/10

デフォルトで、最新版とCPUアーキテクチャ(amd64)と、コンテナが選ばれて起動します。

centos を起動する場合

CentOS を起動するときは次のようにする。

images:XXX の images:を付けるのが重要

lxc launch images:centos/8 

ubuntu 以外は名前空間が違うので注意

ubuntu 以外のイメージを使うときは、images:XXX の images:を付けるのが重要

lxc launch ubuntu:18.04 ubuntu1804
lxc launch images:debian/10
lxc launch images:centos/8 --storage bt01

ubuntu だけは、ubuntu を先頭につけるのですが、ubuntu:18.04 でインストールできるからといって debian:10 でインストールできるわけではありません。最初のうちはよく間違うので注意。

ubuntus: と images:という : セミコロンが配布サーバを指定する名前空間だと思って置くとベター。

centos を検索するといっぱいあります

grep すると長いので、ある程度わかっていたら、名前を入れたほうが速い。

takuya@:~$ lxc image list images:centos
+----------------------------------+--------------+--------+------------------------------------------+--------------+-----------------+----------+-------------------------------+
|              ALIAS               | FINGERPRINT  | PUBLIC |               DESCRIPTION                | ARCHITECTURE |      TYPE       |   SIZE   |          UPLOAD DATE          |
+----------------------------------+--------------+--------+------------------------------------------+--------------+-----------------+----------+-------------------------------+
| centos/6 (3 more)                | 047d1e4bbd22 | yes    | Centos 6 amd64 (20200714_07:08)          | x86_64       | CONTAINER       | 75.83MB  | Jul 14, 2020 at 12:00am (UTC) |
+----------------------------------+--------------+--------+------------------------------------------+--------------+-----------------+----------+-------------------------------+
| centos/6/cloud (1 more)          | 1f2c57f63c95 | yes    | Centos 6 amd64 (20200714_07:08)          | x86_64       | CONTAINER       | 84.13MB  | Jul 14, 2020 at 12:00am (UTC) |
+----------------------------------+--------------+--------+------------------------------------------+--------------+-----------------+----------+-------------------------------+
| centos/6/cloud/i386              | 50fb77c012f1 | yes    | Centos 6 i386 (20200714_07:08)           | i686         | CONTAINER       | 84.26MB  | Jul 14, 2020 at 12:00am (UTC) |
+----------------------------------+--------------+--------+------------------------------------------+--------------+-----------------+----------+-------------------------------+
| centos/6/i386 (1 more)           | dd5ca34a8695 | yes    | Centos 6 i386 (20200714_07:08)           | i686         | CONTAINER       | 75.96MB  | Jul 14, 2020 at 12:00am (UTC) |
+----------------------------------+--------------+--------+------------------------------------------+--------------+-----------------+----------+-------------------------------+
| centos/7 (3 more)                | a007f18afb7c | yes    | Centos 7 amd64 (20200714_07:08)          | x86_64       | VIRTUAL-MACHINE | 417.25MB | Jul 14, 2020 at 12:00am (UTC) |
+----------------------------------+--------------+--------+------------------------------------------+--------------+-----------------+----------+-------------------------------+
| centos/7 (3 more)                | eeecaeac13c8 | yes    | Centos 7 amd64 (20200714_07:08)          | x86_64       | CONTAINER       | 83.16MB  | Jul 14, 2020 at 12:00am (UTC) |
+----------------------------------+--------------+--------+------------------------------------------+--------------+-----------------+----------+-------------------------------+
| centos/7/armhf (1 more)          | b8a283e1740c | yes    | Centos 7 armhf (20200714_07:08)          | armv7l       | CONTAINER       | 78.95MB  | Jul 14, 2020 at 12:00am (UTC) |
+----------------------------------+--------------+--------+------------------------------------------+--------------+-----------------+----------+-------------------------------+
| centos/7/cloud (1 more)          | 89fee0193ddd | yes    | Centos 7 amd64 (20200714_07:08)          | x86_64       | VIRTUAL-MACHINE | 420.13MB | Jul 14, 2020 at 12:00am (UTC) |
+----------------------------------+--------------+--------+------------------------------------------+--------------+-----------------+----------+-------------------------------+
| centos/7/cloud (1 more)          | b3b9407c1839 | yes    | Centos 7 amd64 (20200714_07:08)          | x86_64       | CONTAINER       | 89.75MB  | Jul 14, 2020 at 12:00am (UTC) |
+----------------------------------+--------------+--------+------------------------------------------+--------------+-----------------+----------+-------------------------------+
| centos/7/cloud/armhf             | 483310afd026 | yes    | Centos 7 armhf (20200714_08:11)          | armv7l       | CONTAINER       | 85.35MB  | Jul 14, 2020 at 12:00am (UTC) |
+----------------------------------+--------------+--------+------------------------------------------+--------------+-----------------+----------+-------------------------------+
| centos/7/cloud/i386              | 3b176216218d | yes    | Centos 7 i386 (20200714_07:08)           | i686         | CONTAINER       | 90.55MB  | Jul 14, 2020 at 12:00am (UTC) |
+----------------------------------+--------------+--------+------------------------------------------+--------------+-----------------+----------+-------------------------------+
| centos/7/i386 (1 more)           | 34ebc449e97f | yes    | Centos 7 i386 (20200714_07:08)           | i686         | CONTAINER       | 83.72MB  | Jul 14, 2020 at 12:00am (UTC) |
+----------------------------------+--------------+--------+------------------------------------------+--------------+-----------------+----------+-------------------------------+
| centos/8 (3 more)                | 3c980b7f2b1d | yes    | Centos 8 amd64 (20200714_07:08)          | x86_64       | VIRTUAL-MACHINE | 472.31MB | Jul 14, 2020 at 12:00am (UTC) |
+----------------------------------+--------------+--------+------------------------------------------+--------------+-----------------+----------+-------------------------------+
| centos/8 (3 more)                | 25188125674b | yes    | Centos 8 amd64 (20200714_07:08)          | x86_64       | CONTAINER       | 125.23MB | Jul 14, 2020 at 12:00am (UTC) |
+----------------------------------+--------------+--------+------------------------------------------+--------------+-----------------+----------+-------------------------------+
| centos/8-Stream (3 more)         | 472c6fbd783d | yes    | Centos 8-Stream amd64 (20200714_07:08)   | x86_64       | VIRTUAL-MACHINE | 488.50MB | Jul 14, 2020 at 12:00am (UTC) |
+----------------------------------+--------------+--------+------------------------------------------+--------------+-----------------+----------+-------------------------------+
| centos/8-Stream (3 more)         | fac6147bf59b | yes    | Centos 8-Stream amd64 (20200714_07:08)   | x86_64       | CONTAINER       | 136.46MB | Jul 14, 2020 at 12:00am (UTC) |
+----------------------------------+--------------+--------+------------------------------------------+--------------+-----------------+----------+-------------------------------+
| centos/8-Stream/arm64 (1 more)   | 914ae88a4981 | yes    | Centos 8-Stream arm64 (20200714_07:08)   | aarch64      | CONTAINER       | 132.72MB | Jul 14, 2020 at 12:00am (UTC) |
+----------------------------------+--------------+--------+------------------------------------------+--------------+-----------------+----------+-------------------------------+
| centos/8-Stream/cloud (1 more)   | 284967f0a5a9 | yes    | Centos 8-Stream amd64 (20200712_07:08)   | x86_64       | VIRTUAL-MACHINE | 511.88MB | Jul 12, 2020 at 12:00am (UTC) |
+----------------------------------+--------------+--------+------------------------------------------+--------------+-----------------+----------+-------------------------------+
| centos/8-Stream/cloud (1 more)   | eb677b861e46 | yes    | Centos 8-Stream amd64 (20200714_07:08)   | x86_64       | CONTAINER       | 151.26MB | Jul 14, 2020 at 12:00am (UTC) |
+----------------------------------+--------------+--------+------------------------------------------+--------------+-----------------+----------+-------------------------------+
| centos/8-Stream/cloud/arm64      | 88bafb10fa38 | yes    | Centos 8-Stream arm64 (20200714_07:08)   | aarch64      | CONTAINER       | 147.17MB | Jul 14, 2020 at 12:00am (UTC) |
+----------------------------------+--------------+--------+------------------------------------------+--------------+-----------------+----------+-------------------------------+
| centos/8-Stream/cloud/ppc64el    | 15eaf9ce55a4 | yes    | Centos 8-Stream ppc64el (20200714_07:08) | ppc64le      | CONTAINER       | 155.66MB | Jul 14, 2020 at 12:00am (UTC) |
+----------------------------------+--------------+--------+------------------------------------------+--------------+-----------------+----------+-------------------------------+
| centos/8-Stream/ppc64el (1 more) | 6cedfe83c6b9 | yes    | Centos 8-Stream ppc64el (20200714_07:08) | ppc64le      | CONTAINER       | 140.54MB | Jul 14, 2020 at 12:00am (UTC) |
+----------------------------------+--------------+--------+------------------------------------------+--------------+-----------------+----------+-------------------------------+
| centos/8/arm64 (1 more)          | afb6965dbdfb | yes    | Centos 8 arm64 (20200714_07:08)          | aarch64      | CONTAINER       | 121.66MB | Jul 14, 2020 at 12:00am (UTC) |
+----------------------------------+--------------+--------+------------------------------------------+--------------+-----------------+----------+-------------------------------+
| centos/8/cloud (1 more)          | 6099bb04dc55 | yes    | Centos 8 amd64 (20200714_07:08)          | x86_64       | CONTAINER       | 140.05MB | Jul 14, 2020 at 12:00am (UTC) |
+----------------------------------+--------------+--------+------------------------------------------+--------------+-----------------+----------+-------------------------------+
| centos/8/cloud (1 more)          | f6d70e969faf | yes    | Centos 8 amd64 (20200714_07:08)          | x86_64       | VIRTUAL-MACHINE | 496.13MB | Jul 14, 2020 at 12:00am (UTC) |
+----------------------------------+--------------+--------+------------------------------------------+--------------+-----------------+----------+-------------------------------+
| centos/8/cloud/arm64             | b54ec18a6fdc | yes    | Centos 8 arm64 (20200714_07:08)          | aarch64      | CONTAINER       | 136.18MB | Jul 14, 2020 at 12:00am (UTC) |
+----------------------------------+--------------+--------+------------------------------------------+--------------+-----------------+----------+-------------------------------+
| centos/8/cloud/ppc64el           | 1011e9c98bda | yes    | Centos 8 ppc64el (20200714_07:08)        | ppc64le      | CONTAINER       | 144.22MB | Jul 14, 2020 at 12:00am (UTC) |
+----------------------------------+--------------+--------+------------------------------------------+--------------+-----------------+----------+-------------------------------+
| centos/8/ppc64el (1 more)        | 2df6d6ca3e80 | yes    | Centos 8 ppc64el (20200714_07:08)        | ppc64le      | CONTAINER       | 129.11MB | Jul 14, 2020 at 12:00am (UTC) |
+----------------------------------+--------------+--------+------------------------------------------+--------------+-----------------+----------+-------------------------------+

おおいね。CPUアーキテクチャとかクラウド向けとかいろいろあって大変です。

2021-06-17

いくつかの要素が混じりすぎてて、後で読みにくかったので、CentOSに関するところを別の記事に仕立て直した。

https://takuya-1st.hatenablog.jp/entry/2021/06/17/164311