纸上得来终觉浅:lxd初体验
还记得我写过的lxc初体验嘛?在那篇帖子中,我曾经说过lxd是lxc的进化版,这篇文章中我们来测试一下lxd。
(图源 :pixabay)
安装
如果还没有安装lxd,那么我们需要如下步骤来安装lxd并且让当前用户可以直接使用lxd的相关命令。
安装lxd
sudo apt install lxd
登出并重新登录当前用户,以刷新组成员信息,或者使用如下指令:
newgrp lxd
在一台新的VPS上,我进行这样的操作后,也无法直接只用诸如lxc list
等命令,出现下列错误:
Error: Get http://unix.socket/1.0: dial unix /var/lib/lxd/unix.socket: connect: permission denied
只好手工把用户添加到组lxd中:
sudo usermod -a -G lxd $(whoami)
可以使用groups
命令来检查关联组别是否成功。
lxd初始化
在正式开始之前,我们还需要执行lxd init
来进行一些初始化设置(网络、存储等等)。
lxd init
我们都选择默认设置即可(空间我设置的5G,因为我磁盘空间比较紧张):
查询/创建/使用容器
查询
在进行完上述设置后,我们可以使用如下命令查询我们机器上的lxd容器:
lxc list
可以看到我们现在一个容器都没有呢:
注:lxc并非之前文章中的lxc,本文中代表的是lxd的客户端。
创建
下面来创建我们的第一个lxd容器:
lxc launch ubuntu:18.04 first
创建后,容器会自动启动:
再来查询一下:
lxc list
耶,有了一个(我有些后悔,初始化的时候应该关闭ipv6,看着闹心):
使用
我们可以使用如下命令进入到对应的容器中:
lxc exec first -- /bin/bash
或者执行命令,拉取文件,推送文件等:
lxc exec first -- apt-get update
lxc file pull first/etc/hosts .
lxc file push hosts first/tmp/
至于关闭和开启可以用如下命令:
lxc stop first
lxc start first
不需要了,可以用以下命令删除:
lxc delete first
开了一大堆自己玩,哈哈:
是不是很好玩的样子,感兴趣的朋友也试试吧。
相关链接
- 纸上得来终觉浅:lxc初体验
- LXD Getting started - command line
- https://www.ubuntu.org.cn/cloud/lxd
- https://linuxcontainers.org/lxd/try-it/
https://steemit.com/~witnesses type in
oflyhigh
and click VOTE
![](https://steemitimages.com/640x0/https://cdn.steemitimages.com/DQmX5NysqT44FBa3bhuWqQ69nAbseu8Nt5YQPn2pYejPVxA/image.png)
Vote @oflyhigh via Steemconnect
Thank you!
!thumbup
恭喜你!您的这篇文章入选 @justyy 今日 (2019-11-13) 榜单 【优秀的文章】, 回复本条评论24小时内领赏,点赞本评论将支持 @dailychina 并增加将来您的奖赏。
@justyy 是CN区的见证人,请支持他,给他投票,或者设置justyy为见证人代理。感谢!@justyy的主要贡献:https://steemyy.com
Congratulations! This post has been selected by @justyy as today's (2019-11-13) 【Good Posts】, Steem On! Reply to this message in 24 hours to get rewards. Upvote this comment to support the @dailychina and increase your future rewards! ^_^
SteemIt 工具、API接口、机器人和教程
SteemIt Tools, Bots, APIs and Tutorial
If you believe what I am doing, please consider a spare vote voting me here, thank you very much indeed.
@justyy - the author of https://SteemYY.com and I have been a Steem Witness for more than a year now.
Thank you so much for participating in the Partiko Delegation Plan Round 1! We really appreciate your support! As part of the delegation benefits, we just gave you a 3.23% upvote! Together, let’s change the world!