LoginSignup
14
13

More than 5 years have passed since last update.

CentOS上の lxc でCentOS のコンテナを走らせる

Last updated at Posted at 2014-08-06

CentOS に lxc-1.0.5 を入れる

LXC - Linux Containers

specファイルからRPM作ってインストール

$ curl -O https://linuxcontainers.org/downloads/lxc-1.0.5.tar.gz
$ tar zxvf lxc-1.0.5.tar.gz
$ mkdir -p ~/src/rpm/SPECS ~/src/rpm/SOURCES
$ cp lxc-1.0.5/lxc.spec ~/src/rpm/SPECS
$ cp lxc-1.0.5.tar.gz ~/src/rpm/SOURCES
$ rpmbuild -bb ~/src/rpm/SPECS/lxc.spec
$ cd  ~/src/rpm/RPMS/x86_64
$ sudo rpm -ivh lxc-1.0.5-1.el6.x86_64.rpm lxc-libs-1.0.5-1.el6.x86_64.rpm

その他 libvirt , docbook2X, cgconfig が必要

template から Linux コンテナを作成する

テンプレートは以下にある

$ ls /usr/share/lxc/templates
lxc-alpine     lxc-centos    lxc-fedora        lxc-oracle  lxc-ubuntu-cloud
lxc-altlinux   lxc-cirros    lxc-gentoo        lxc-plamo
lxc-archlinux  lxc-debian    lxc-openmandriva  lxc-sshd
lxc-busybox    lxc-download  lxc-opensuse      lxc-ubuntu

busybox は最も単純なLinuxコンテナ、sshd は SSHデーモンのあるLinuxコンテナ。

$ sudo lxc-create -t centos -n centos-test1
$ sudo lxc-start -n centos-test1 -d
lxc-start: Executing '/sbin/init' with no configuration file may crash the host

エラーがでるので -f /var/lib/lxc/centos-test1/config を指定する

$ sudo lxc-start -f /var/lib/lxc/centos-test1/config -n centos-test1 -d
lxc_conf - failed to attach 'vethPX7X32' to the bridge 'virbr0' : No such device

またエラー。仮想ブリッジがない。設定かえてリブート。

$ sudo vi /etc/sysctl.conf
net.ipv4.ip_forward = 1
$ sudo shutdown -r now

再度実行するとプロンプトがでてくる。
2回目以降は -f オプションは不要みたい。
パスワードは、/var/lib/lxc/centos-test1/tmp_root_pass に定義されているが、
初回に変更する必要あり。

$ sudo lxc-start -f /var/lib/lxc/centos-test1/config -n centos-test1 -d
$ sudo lxc-console -n centos-test1
CentOS release 6.5 (Final)
Kernel 2.6.32-431.20.3.el6.x86_64 on an x86_64

centos-test1 login: root
Password:
Last login: Wed Aug  6 01:40:45 on lxc/console
[root@centos-test1 ~]#

停止するには仮想コンテナで shutdown を実行するか、lxc-stop を使って停止する。

14
13
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
14
13