2017年1月2日月曜日

LXC を試してみました

環境

  • Ubuntu 16.04.1 LTS (xenial) Server

LXC をインストール

$ sudo apt install lxc

以下のようにテンプレートができました。

$ ls -la /usr/share/lxc/templates/
total 412
drwxr-xr-x 2 root root  4096 Jan  2 14:52 .
drwxr-xr-x 6 root root  4096 Jan  2 14:52 ..
-rwxr-xr-x 1 root root 13160 Dec 16 03:43 lxc-alpine
-rwxr-xr-x 1 root root 13704 Dec 16 03:43 lxc-altlinux
-rwxr-xr-x 1 root root 11373 Dec 16 03:43 lxc-archlinux
-rwxr-xr-x 1 root root 12159 Dec 16 03:43 lxc-busybox
-rwxr-xr-x 1 root root 29725 Dec 16 03:43 lxc-centos
-rwxr-xr-x 1 root root 10374 Dec 16 03:43 lxc-cirros
-rwxr-xr-x 1 root root 20312 Dec 16 03:43 lxc-debian
-rwxr-xr-x 1 root root 17914 Dec 16 03:43 lxc-download
-rwxr-xr-x 1 root root 49693 Dec 16 03:43 lxc-fedora
-rwxr-xr-x 1 root root 28384 Dec 16 03:43 lxc-gentoo
-rwxr-xr-x 1 root root 13868 Dec 16 03:43 lxc-openmandriva
-rwxr-xr-x 1 root root 16088 Dec 16 03:43 lxc-opensuse
-rwxr-xr-x 1 root root 41791 Dec 16 03:43 lxc-oracle
-rwxr-xr-x 1 root root 11570 Dec 16 03:43 lxc-plamo
-rwxr-xr-x 1 root root 19242 Dec 16 03:43 lxc-slackware
-rwxr-xr-x 1 root root 26862 Dec 16 03:43 lxc-sparclinux
-rwxr-xr-x 1 root root  6862 Dec 16 03:43 lxc-sshd
-rwxr-xr-x 1 root root 25705 Dec 16 03:43 lxc-ubuntu
-rwxr-xr-x 1 root root 11734 Dec 16 03:43 lxc-ubuntu-cloud

コンテナ環境作成

$ sudo lxc-create -t ubuntu -n lxc_ubuntu
... snip ...
Current default time zone: 'Etc/UTC'
Local time is now:      Mon Jan  2 06:30:58 UTC 2017.
Universal Time is now:  Mon Jan  2 06:30:58 UTC 2017.


##
# The default user is 'ubuntu' with password 'ubuntu'!
# Use the 'sudo' command to run tasks as root in the container.
##
  • インストールが完了するまで、それなりに時間がかかります。

コンテナのディレクトリが作成されました。

$ sudo ls -la /var/lib/lxc
total 12
drwx------  3 root root 4096 Jan  2 14:56 .
drwxr-xr-x 45 root root 4096 Jan  2 14:52 ..
drwxrwx---  3 root root 4096 Jan  2 15:30 lxc_ubuntu

コンテナ一覧を確認

$ sudo lxc-ls --fancy
NAME       STATE   AUTOSTART GROUPS IPV4 IPV6
lxc_ubuntu STOPPED 0         -      -    -

コンテナを起動

$ sudo lxc-start -n lxc_ubuntu -d

$ sudo lxc-ls --fancy
NAME       STATE   AUTOSTART GROUPS IPV4      IPV6
lxc_ubuntu RUNNING 0         -      10.0.3.69 -

コンテナのコンソールに接続

$ sudo lxc-console -n lxc_ubuntu

Connected to tty 1
                  Type <Ctrl+a q> to exit the console, <Ctrl+a Ctrl+a> to enter Ctrl+a itself

Ubuntu 16.04.1 LTS lxc_ubuntu pts/0

lxc_ubuntu login:
  • デフォルトのログインユーザー ubuntu、パスワード ubuntu

インストールされたディストリビューションを確認

$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 16.04.1 LTS
Release:        16.04
Codename:       xenial

LANG を確認

$ echo $LANG
en_US.UTF-8

タイムゾーンを変更

コンテナインストール直後のタイムゾーン

$ date
Mon Jan  2 07:41:13 UTC 2017

タイムゾーンを変更

$ sudo dpkg-reconfigure tzdata
  • Asia - Tokyo を選択

変更後のタイムゾーン

$ date
Mon Jan  2 16:47:27 JST 2017

コンテナから切断するには <Ctrl+a q>

コンテナを停止する場合はコンテナ内で shutdown コマンドを打つか、ホストで以下を実行

$ sudo lxc-stop -n lxc_ubuntu

$ sudo lxc-ls --fancy
NAME       STATE   AUTOSTART GROUPS IPV4 IPV6
lxc_ubuntu STOPPED 0         -      -    -

0 件のコメント:

コメントを投稿