TOC
个人使用环境:ubuntu20.04 , lxd version : 5.13
lxc remote list
比如访问 ubuntu的image资源,访问 https://cloud-images.ubuntu.com/releases ; 获取下面的信息:
lxc storage list
note: default 为默认的存储地址,lxd_pool 是我创建的存储地址
如何创建 自己的pool
lxc storage create <pool_name> {storage_type} {options}
lxc storage create temp_pool dir source=/tmp/saaa
# 我的系统在storage/tools 挂载了一个btrfs 文件系统
lxc storage create temp_pool brtfs source=/storage/tools
lxc launch|init <image_server>:<image_name> <instance_name> [flags]
使用init 或者 launch ,依赖指定的image创建容器;init 和 launch的区别是
举例:使用远程仓库ubuntu 的 20.04 的释放版本,创建一个名为test 的容器,并指定存储空间为lxd_pool
lxc init ubuntu:22.04 test --storage=lxd_pool
如果默认创建容器时没有带 --storage ,则存储空间默认为 default 的pool;
如果创建容器时,没有命名,则容器自动创建一个名称。
创建好的容器,可以修改存储空间和容器名称
lxc move <old name> <new name> --storage=<pool_name>
ubuntu 默认创建好容器支持ssh;
在主设备中,我使用 device 的 proxy属性,配置宿主机和容器的ssh端口映射,客户端可以通过访问宿主机端口的方式,ssh登录容器。
lxc config device <container name> <config name> proxy <listen option> <connect option >
举例 为刚刚创建的test 容器定义一个proxy_ssh 的配置,将宿主机的 10000 端口映射到容器的ssh端口(22)
lxc config device add test proxy_ssh proxy listen=tcp:0.0.0.0:10000 connect=tcp:0.0.0.0:22
sudo vim /etc/ssh/sshd_config
# 修改完后
sudo /etc/init.d/ssh restart
如何进入容器,参考 2.5
容器默认支持ubuntu 和 root 两个账号,其中ubuntu 支持sudo 组
我们可以直接使用这两个账号访问容器或者自定义账号访问。
^_^ 没有找到root 和 ubuntu的默认密码,可以通过lxc 直接执行容器指令
note:执行容器指令,需要确认容器已经启动
lxc exec <instance_name> -- <command>
举例:修改容器test 的账号ubuntu 密码
lxc exec test -- passwd ubuntu
lxc exec test -- useradd -m test1 -s /bin/bash
lxc exec test -- usermod -G sudo test1
lxc console test
退出命令行使用 <C-a>+q : 按住 ctrl 命令,点击 a, 松开后点击 q
lxc list
lxc config show <container name>
举例:查看创建的test 容器配置
lxc config show test
lxc stop <container name>
举例: 停止创建的test 容器配置
lxc stop test
lxc start <container name>
举例: 启动创建的test 容器配置
lxc start test
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。