我想开始尝试容器,所以我遵循了本教程并做了:
sudo apt-get install lxd lxd-client zfsutils-linux
sudo lxd init
并回答了以下问题
Do you want to configure a new storage pool (yes/no) [default=yes]? yes
Name of the storage backend to use (dir or zfs) [default=zfs]: zfs
Create a new ZFS pool (yes/no) [default=yes]? yes
Name of the new ZFS pool [default=lxd]: lxd
Would you like to use an existing block device (yes/no) [default=no]? no
Size in GB of the new loop device (1GB minimum) [default=20]: 20
Would you like LXD to be available over the network (yes/no) [default=no]? no
Do you want to configure the LXD bridge (yes/no) [default=yes]? yes
---- following questions in a whiptail window (always accepting defaults)
Would you like to setup a network bridge for LXD containers now? yes
Bridge interface name? lxdbr0
Do you want to setup an IPv4 subnet? yes
IPv4 network address? 10.12.8.1
IPv4 CIDR mask? 24
First DHCP address? 10.12.8.2
Last DHCP address? 10.12.8.254
Max number of DHCP clients? 252
Do you want to NAT the IPv4 traffic? yes
Do you want to setup an IPv6 subnet? no
之后命令成功结束
Warning: Stopping lxd.service, but it can still be activated by:
lxd.socket
LXD has been successfully configured.
现在测试第一个容器:
lxc launch ubuntu:x test
lxc list
其输出为
+------+---------+------+------+------------+-----------+
| NAME | STATE | IPV4 | IPV6 | TYPE | SNAPSHOTS |
+------+---------+------+------+------------+-----------+
| test | RUNNING | | | PERSISTENT | 0 |
+------+---------+------+------+------------+-----------+
显然容器没有网络访问权限。所以我开始寻找解决方案:有很多关于类似问题的报告,例如这,这或者这,但对我而言,它们似乎都没有什么帮助。
系统信息(如果有用):
matpen@ubuntu:~$ cat /etc/lsb-release
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=16.04
DISTRIB_CODENAME=xenial
DISTRIB_DESCRIPTION="Ubuntu 16.04.4 LTS"
matpen@ubuntu:~$ uname -a
Linux ubuntu 4.4.0-121-generic #145-Ubuntu SMP Fri Apr 13 13:47:23 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux
matpen@ubuntu:~$ lxc --version
2.0.11
matpen@ubuntu:~$ lxc profile show default
config:
environment.http_proxy: ""
user.network_mode: dhcp
description: Default LXD profile
devices:
eth0:
name: eth0
nictype: macvlan
parent: lxdbr0
type: nic
name: default
used_by: []
matpen@ubuntu:~$ ifconfig
enp2s0 Link encap:Ethernet HWaddr 00:25:22:8f:49:82
inet addr:192.168.0.2 Bcast:192.168.0.255 Mask:255.255.255.0
inet6 addr: fd1d:9e7b:b584::da3/128 Scope:Global
inet6 addr: fd1d:9e7b:b584:0:5d78:aa1e:1955:9bc0/64 Scope:Global
inet6 addr: fe80::f449:e467:b182:4668/64 Scope:Link
inet6 addr: fd1d:9e7b:b584:0:60ab:f8f4:f1dc:eb1e/64 Scope:Global
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:248459 errors:0 dropped:0 overruns:0 frame:0
TX packets:167050 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:315015380 (315.0 MB) TX bytes:34408870 (34.4 MB)
lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
inet6 addr: ::1/128 Scope:Host
UP LOOPBACK RUNNING MTU:65536 Metric:1
RX packets:6405 errors:0 dropped:0 overruns:0 frame:0
TX packets:6405 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1
RX bytes:595013 (595.0 KB) TX bytes:595013 (595.0 KB)
lxdbr0 Link encap:Ethernet HWaddr 00:00:00:00:00:00
inet addr:10.12.8.1 Bcast:0.0.0.0 Mask:255.255.255.0
inet6 addr: fe80::fc06:77ff:fe8f:f471/64 Scope:Link
UP BROADCAST MULTICAST MTU:1500 Metric:1
RX packets:111 errors:0 dropped:0 overruns:0 frame:0
TX packets:120 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:25968 (25.9 KB) TX bytes:14451 (14.4 KB)
virbr0 Link encap:Ethernet HWaddr 00:00:00:00:00:00
inet addr:192.168.122.1 Bcast:192.168.122.255 Mask:255.255.255.0
UP BROADCAST MULTICAST MTU:1500 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:0 (0.0 B) TX bytes:0 (0.0 B)