目的
LXC(Linux Container)を触ってみた際の備忘録です
LXC
LXC(英語: Linux Containers)は、1つのLinuxカーネルを実行しているコントロールホスト上で、複数の隔離されたLinuxシステム(コンテナ)を走らせる、OSレベル仮想化のソフトウェアである。
作業環境はubuntu16.04LTSです
LXCのインストール
sudo apt-get install lxc
お試しでubuntu16.04(xenial)のコンテナを使う
コンテナのテンプレートをダウンロードする
$ sudo lxc-create -t download -n test-container
Setting up the GPG keyring
Downloading the image index
---
DIST RELEASE ARCH VARIANT BUILD
---
...
ubuntu xenial arm64 default 20200620_07:42
Distribution:
ubuntu
Release:
xenial
Architecture:
amd64
Downloading the image index
Downloading the rootfs
Downloading the metadata
The image cache is now ready
Unpacking the rootfs
---
You just created an Ubuntu xenial amd64 (20200620_07:42) container.
To enable SSH, run: apt install openssh-server
No default root or user password are set by LXC.
起動
sudo lxc-start -n test-container -d
起動確認
$ sudo lxc-ls -f
NAME STATE AUTOSTART GROUPS IPV4 IPV6
test-container RUNNING 0 - 10.0.3.143 -
コンテナ情報を確認
$ sudo lxc-info -n test-container
Name: test-container
State: RUNNING
PID: 20646
IP: 10.0.3.143
CPU use: 0.32 seconds
BlkIO use: 24.00 KiB
Memory use: 11.85 MiB
KMem use: 0 bytes
Link: vethQTF7PV
TX bytes: 1.13 KiB
RX bytes: 1.32 KiB
Total bytes: 2.46 KiB
コンテナへログイン
sudo lxc-attach -n test-container
コマンドを実行してlsb_releaseを確認
root@test-container:~# lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 16.04.6 LTS
Release: 16.04
Codename: xenial
ログアウト
$ exit
コンテナを停止
$ sudo lxc-stop -n test-container
コンテナを破棄
$ sudo lxc-destroy -n test-container
ubuntu18.04LTS(bionic)の場合
コンテナ作成
$ sudo lxc-create -t download -n test01 -- -d ubuntu -r bionic -a amd64
コマンド実行
$ sudo lxc-start -n test01 -d
ubuntu@ubuntu:~$ sudo lxc-ls -f
NAME STATE AUTOSTART GROUPS IPV4 IPV6
test01 RUNNING 0 - 10.0.3.140 -
ログイン
$ sudo lxc-attach -n test01
root@test01:~# lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 18.04.4 LTS
Release: 18.04
Codename: bionic
ログアウト、停止、破棄
$ exit
$ sudo lxc-stop -n test01
$ sudo lxc-destroy -n test01
Destroyed container test01
containerの基本操作
作成
$ sudo lxc-create ...(オプションは-hで確認)
起動
$ sudo lxc-start -n (container name)
ログイン
$ sudo lxc-attach -n (container name)
終了
$ sudo lxc-stop -n (container name)
破棄
$ sudo lxc-destroy -n (container name)
感想
操作感がdockerと似ている
参考
LXCで学ぶコンテナ入門 -軽量仮想化環境を実現する技術 第8回 LXCの基本操作[1]
第5回 LinuxコンテナとDockerの違いをざっくりと比較する
15分で分かるLXC(Linux Containers)の仕組みと基本的な使い方
LXC (Linux Container) を使い超軽量作業環境を手に入れよう
hagix9/lxc-centos
LXC 1.0: 最初のUbuntuコンテナー [1/10]
Ubuntu
Docker だけじゃない Containers の世界
LXC
LXD 2.0: イメージの管理 [5/12]
Debian on LXC/LXD
LXD はじめに - コマンドライン