PVE安装Debian的LXC容器运行Docker

PVE安装Debian的LXC容器运行docker

检测PVE虚拟系统是否支持虚拟化
PVE虚拟出来的vm系统的cpu,默认不支持vmx,即不支持嵌套虚拟化,在虚拟机中使用命令来验证

1
2
#没有输出即不支持,否则会高亮显示vmx或者svm。
egrep --color 'vmx|svm' /proc/cpuinfo

一、开启嵌套虚拟化步骤

  1. 关闭所有虚拟机,开启pve主机的nested

检查pve系统是否开启nested,运行命令:

1
2
3
#输出N,表示未开启,输出Y,表示已开启
cat /sys/module/kvm_intel/parameters/nested
Y
  1. 检查结果未开启,必须关闭所有的虚拟机系统,否则不能开启内核支持。
1
2
3
4
modprobe -r kvm_intel
modprobe kvm_intel nested=1
# 再次检查nested,输出Y,即为开启成功。
cat /sys/module/kvm_intel/parameters/nested

如果报错Module kvm_intel is in use,请检查你的虚拟机是否全部关闭。

  1. 设置系统启动后自动开启nested
1
echo "options kvm_intel nested=1" >> /etc/modprobe.d/modprobe.conf

创建Debian 12的LXC容器

二、PVE映射LXC权限

1
2
3
4
5
6
#101为容器的编号
nano /etc/pve/lxc/101.conf
#添加以下内容
lxc.apparmor.profile: unconfined
lxc.cgroup.devices.allow: a
lxc.cap.drop:

设置Debian LXC
选项,开机启动,设置为 是
选项,功能,勾选嵌套、NFS、SMB/CIFS,方便后续安装docker
控制台,使用root&密码进入终端

三、Debian换源

  1. 备份原文件
1
mv /etc/apt/sources.list /etc/apt/sources.list.bak
  1. 更换清华源
1
2
3
4
5
6
7
8
9
10
11
12
13
14
nano /etc/apt/sources.list

#复制以下内容
deb https://mirrors.tuna.tsinghua.edu.cn/debian/ bookworm main contrib non-free non-free-firmware
# deb-src https://mirrors.tuna.tsinghua.edu.cn/debian/ bookworm main contrib non-free non-free-firmware

deb https://mirrors.tuna.tsinghua.edu.cn/debian/ bookworm-updates main contrib non-free non-free-firmware
# deb-src https://mirrors.tuna.tsinghua.edu.cn/debian/ bookworm-updates main contrib non-free non-free-firmware

deb https://mirrors.tuna.tsinghua.edu.cn/debian/ bookworm-backports main contrib non-free non-free-firmware
# deb-src https://mirrors.tuna.tsinghua.edu.cn/debian/ bookworm-backports main contrib non-free non-free-firmware

deb https://mirrors.tuna.tsinghua.edu.cn/debian-security bookworm-security main contrib non-free non-free-firmware
# deb-src https://mirrors.tuna.tsinghua.edu.cn/debian-security bookworm-security main contrib non-free non-free-firmware

三、安装Docker

  1. 一键安装脚本
1
curl -s https://get.docker.com/ | sh
  1. 配置Docker开机启动
1
2
3
4
5
6
7
8
9
10
11
#启动
systemctl start docker

# 查看docker状态
docker stats

# 设置开机启动
systemctl enable docker

# 重启系统
reoot
  1. Docker更换国内源
1
2
3
4
5
6
7
8
9
10
11
nano /etc/docker/daemon.json

#复制以下内容
{
"registry-mirrors" : [
"https://registry.docker-cn.com",
"https://docker.mirrors.ustc.edu.cn",
"http://hub-mirror.c.163.com",
"https://cr.console.aliyun.com/"
]
}

四、可选安装CasaOS

  1. 一键安装脚本
1
curl -fsSL https://get.casaos.io | sudo bash