如何在Ubuntu上建立及管理LXC容器?,ubuntu建立lxc容器

來源:互聯網
上載者:User

如何在Ubuntu上建立及管理LXC容器?,ubuntu建立lxc容器
將LXC安裝到Ubuntu上

$ sudo apt-get install lxc

安裝完畢之後,運行lxc-checkconifg工具,檢查當前Linux核心支援LXC的情況。要是一切都已被啟用,核心對LXC的支援已準備就緒。

$ lxc-checkconfig

安裝LXC工具後,你會發現,LXC的預設橋接器介面(lxcbr0)已自動建立(已在/etc/lxc/default.conf中加以配置)。

$ ifconfig lxcbr0

建立LXC容器後,視窗的介面就會自動連接到該橋接器,那樣容器就能與外界進行聯絡了。
建立LXC容器
在/usr/share/lxc/templates目錄下找到可用的LXC模板。
$ ls /usr/share/lxc/templates

1.Create a configration file, named lxc_common.conf:
lxc.network.type = vethlxc.network.flags = uplxc.network.name = eth0lxc.network.link = lxcbr0

2.Change mirrors:
sudo vim /usr/share/lxc/templates/ubuntu

Change this to the faster mirror server you know:
MIRROR=http://archive.ubuntu.com/ubuntuSECURITY_MIRROR=http://security.ubuntu.com/ubuntu

3.LXC模板其實就是一段指令碼而已,用來為某個特定的Linux環境建立容器。你在建立LXC容器時,需要用到這其中一個模板。

比如說,為了建立Ubuntu容器,使用下面這個命令列:
$ sudo lxc-create -n precise -f lxc_common.conf -t ubuntu -- -r precise

4.Configure the network, sudo vim /etc/default/lxc-net, change the configs if you like, I have uncomment this line:
LXC_DHCP_CONFILE=/etc/lxc/dnsmasq.conf

5.Use a fixed ip address for “precise” container, sudo vim /etc/lxc/dnsmasq.conf:
dhcp-host=precise,10.0.3.2

管理LXC容器
既然我們已知道了如何建立及啟動LXC容器,現在不妨看看我們可以如何處理運行中的容器。
首先,我們想要訪問容器的控制台。為此,鍵入這個命令:
$ sudo lxc-console -n precise
Restart lxc-net:
$ sudo service lxc-net restart

Start the lxc container:
$ sudo lxc-start -n precise
Stop the lxc container:
$ sudo lxc-stop -n precise

詳細內容請看:LXC安裝與配置

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.