Avatar

Organizations

2 results for Container
  • 1. 在LXC容器下安装

    修改特权容器

    LXC容器必须是特权容器,但创建CT时,默认为非特权容器,要特别注意!!!

    nano /etc/pve/lxc/<CTID>.conf
    
    • 删除或注释掉 unprivileged: 1 这一行。
    • 确保没有 lxc.idmap 相关的UID/GID映射配置(如有则删除)。
    • Web UI -> LXC 容器 -> 选项 (Options) -> 功能 (Features) -> 编辑 (Edit)
      • 勾选 FUSE
      • 勾选 嵌套

    2. 安装

    Debian

    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
    

    AlmaLinux

    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
    

    3. 加速

    国内镜像源与代理二选一,但考虑到未来的日常使用,还是换源简单一些。

    linux podman container Created Tue, 22 Jul 2025 18:49:39 +0800
  • Image 列表

    [docker | podman] image ls -a
    # or
    [docker | podman] images
    

    Container 列表

    [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
    

    删除冗余 Image

    echo 'y'  |  [docker | podman] system prune
    

    导入/导出 Image

    # 导出
    [docker | podman] save -o <image>.tar <image_name:label  |  image_id>
    # 导入
    # 使用image_id导出的Image ,导入时也没有名字
    [docker | podman] load -i <image>.tar
    

    导入/导出 Volume

    # 导出数据
    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> -
    

    不启动 Image ,查看 Image 内的文件

    # 创建临时容器
    [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]
    

    [docker | podman]快捷命令

    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
    
    CLI docker podman container Created Thu, 13 Jan 2022 22:20:52 +0800