获取完整的Ubuntu镜像列表:
lxc image list ubuntu:
lxc image list ubuntu-daily:
获取所有非官方镜像列表:
lxc image list images:
获取所有带别名的镜像列表,比如在“ubuntu:”标签下:
lxc image alias list ubuntu:
获取所有容器:
lxc list
你可以将很多的参数传入这个命令来改变列表栏呈现的内容。但是如果一个系统中有大量的容器存在,默认的列表栏呈现方式会显得比较慢(由于需要从容器中获得网络信息),不过你可以这样做:
lxc list --fast
结果只会呈现那些较少需要服务端协同处理的列表栏。
你也可以根据容器名或者某个参数进行过滤:
stgraber@dakara:~$ lxc config show --expanded zerotier
name: zerotier
profiles:
- default
config:
security.nesting: "true"
user.a: b
volatile.base_image: a49d26ce5808075f5175bf31f5cb90561f5023dcd408da8ac5e834096d46b2d8
volatile.eth0.hwaddr: 00:16:3e:ec:65:a8
volatile.last_state.idmap: '[{"Isuid":true,"Isgid":false,"Hostid":100000,"Nsid":0,"Maprange":65536},{"Isuid":false,"Isgid":true,"Hostid":100000,"Nsid":0,"Maprange":65536}]'
devices:
eth0:
name: eth0
nictype: macvlan
parent: eth0
type: nic
limits.ingress: 10Mbit
limits.egress: 10Mbit
root:
path: /
size: 30GB
type: disk
path: /dev/net/tun
type: unix-char
ephemeral: false
That one is very convenient to check what will actually be applied to a given container.
stgraber@dakara:~$ lxc exec zerotier --env mykey=myvalue env | grep mykey
mykey=myvalue
Because LXD has direct access to the container’s file system, it can directly read and write any file inside the container. This can be very useful to pull log files or exchange files with the container.由于LXD能进入容器的文件系统,所以可以直接读写容器中的任何文件。这一点对容器中日志文件的拉取或者文件的交换非常有用。
这是一个很方便的功能:从指定的路径拉取一个文件,在你的默认文本编辑器中打开,最后当你关闭这个文件时会传递回该容器中。
lxc file edit <container>/<path>
LXD lets you snapshot and restore containers. Snapshots include the entirety of the container’s state (including running state if –stateful is used), which means all container configuration, container devices and the container file system.LXD允许你给容器打快照,也支持快照恢复。快照中包含容器的整个状态(包括运行时状态,如果使用了-stateful参数的话):容器所有的配置,设备以及文件系统。> lxc snapshot <container>这将会得到一个名为snapX的快照,其中X是一个递增的数字。你也可以命名快照:
lxc snapshot <container> <snapshot name>
“lxc list”可得到容器中的快照数量,但实际快照列表只在“lxc info”中可见。
lxc info <container>
> lxc restore <container> <snapshot name>
LXD lets you copy and move containers between hosts, but that will get covered in a later post.LXD允许你在不同的主机间复制和搬移容器,这将会在下个博文中进行讨论。目前,“move”命令可以用来重命名一个容器:
lxc move <old name> <new name>
这里有一个要求,容器必须是停止的状态,那么容器里面的一切都会原样保存,包括冲突的信息(MAC地址等等)。这篇长文覆盖了大多数平时运维需要用到的命令。显然易见的是很多这些命令都有额外的参数,帮助你更有效地使用LXD容器和调整专门的容器配置。学习这些命令的最好方法就是看看它们的帮助文档(增加–help的参数)。