LXC容器必须是特权容器,但创建CT时,默认为非特权容器,要特别注意!!!
nano /etc/pve/lxc/<CTID>.conf
apt update \
&& apt install -y curl gpg gnupg2
# 查看 Debian版本
apt install -y lsb-release \
&& lsb_release -a
# if Debian Release == 13
# 添加 Kubic 项目的 Debian_Testing 软件源
echo 'deb http://download.opensuse.org/repositories/devel:/kubic:/libcontainers:/stable/Debian_Testing/ /' | sudo tee /etc/apt/sources.list.d/kubic.list
# 下载并添加对应的 GPG 密钥
curl -fsSL https://download.opensuse.org/repositories/devel:kubic:libcontainers:stable/Debian_Testing/Release.key | gpg --dearmor | sudo tee /etc/apt/trusted.gpg.d/kubic.gpg > /dev/null
# 更新软件包列表并安装 Podman
apt update \
&& apt install -y podman \
&& podman version
# 安装 podman-compose
apt install -y pipx \
&& pipx ensurepath \
&& . ~/.bashrc \
&& pipx install podman-compose \
&& podman-compose version
# iptables必须安装,否则netavark无法运行
apt install -y iptables
# 防火墙一定要加这条,否则容器之间的名称解析无法工作
iptables -A INPUT -p udp -m udp --dport 53 -j ACCEPT
dnf install -y podman python3 python3-pip \
&& podman --version ; podman info \
&& python3 -m pip install --upgrade pip \
&& python3 -m pip install podman-compose \
&& podman-compose -v \
&& systemctl enable podman-restart.service \
&& systemctl start podman-restart.service
国内镜像源与代理二选一,但考虑到未来的日常使用,还是换源简单一些。
[docker | podman] image ls -a
# or
[docker | podman] images
[docker | podman] container ls -a
# or
[docker | podman] ps
[docker | podman] compose -f <yaml_file> logs [-f] [service name]
# or
[docker | podman] logs [-f] [container id]
[docker | podman] compose -f <yaml_file> config
echo 'y' | [docker | podman] system prune
# 导出
[docker | podman] save -o <image>.tar <image_name:label | image_id>
# 导入
# 使用image_id导出的Image ,导入时也没有名字
[docker | podman] load -i <image>.tar
# 导出数据
podman volume export <volume_name> | gzip > /tmp/<volume_name>_backup.tar.gz
scp /tmp/<volume_name>_backup.tar user@hostname:/tmp/
# 或使用 rsync
rsync -avz /tmp/<volume_name>_backup.tar user@hostname:/tmp/
# 创建目标卷
podman volume create <volume_name>
# 导入数据
gunzip -c /tmp/<volume_name>_backup.tar.gz | podman volume import <volume_name> -
# 创建临时容器
[docker | podman] conatiner create --name <container_name> <image_name>
# 从容器复制文件到宿主机
[docker | podman] conatiner cp <container_name>:<file_path> <dest_path>
# 清理临时窗口
[docker | podman] container rm <container_name>
[docker | podman] network create [name]
echo "alias d-ll='[docker | podman] image ls -a; echo; [docker | podman] container ls -a'" >> ~/.bashrc \
&& echo "alias d-ps='[docker | podman] ps'" >> ~/.bashrc \
&& echo "alias d-clean='[docker | podman] system prune -f'" >> ~/.bashrc \
&& echo "alias d-rm='_a(){ [docker | podman] image rm $1; echo; [docker | podman] container rm $1; }; _a'" >> ~/.bashrc \
&& echo "alias d-exec='_a(){ [docker | podman] exec -it $1 /bin/bash; }; _a'" >> ~/.bashrc \
&& echo "alias d-stop='_a(){ [docker | podman] container stop $1; }; _a'" >> ~/.bashrc \
&& echo "alias d-kill='_a(){ [docker | podman] container kill $1; }; _a'" >> ~/.bashrc
source ~/.bashrc