Avatar

Organizations

2 results for Podman
  • 安装

    apt update
    # 安装 Podman
    apt install -y curl gpg gnupg2
    # 查看 Debian版本
    lsb_release -a
    
    # Debian 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
    pipx install podman-compose
    podman-compose version
    
    # iptables必须安装,否则netavark无法运行
    apt install -y iptables 
    # 防火墙一定要加这条,否则容器之间的名称解析无法工作
    iptables -A INPUT -p udp -m udp --dport 53 -j ACCEPT
    # 测试podman是否安装成功
    podman run --rm hello-world
    

    配置

    # 配置国内镜像源
    sed -E -i.bak \
        -e 's/^# (unqualified-search-registries = ).+$/\1["docker.io"]/' \
        -e 's/^# (\[\[registry\]\])$/\1/' \
        -e 's/^# (prefix = ).+"$/\1"docker.io"/' \
        -e '0,\/^# (location = ).+"$/s//\1"docker.1ms.run"/' \
        -e '0,\/^# (\[\[registry.mirror\]\])$/s//\1/' \
        -e '0,\/^# (location = ).*"$/s//\1"registry.cn-hangzhou.aliyuncs.com"/' \
        /etc/containers/registries.conf
    
    # nano /etc/containers/registries.conf
    unqualified-search-registries = ["docker.io"]
    
    [[registry]]
    prefix = "docker.io"
    location = "docker.1ms.run"
    
    [[registry.mirror]]
    location = "registry.cn-hangzhou.aliyuncs.com"  # 可选备用
    

    其实命令与Docker一致,非常方便好用。

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

    [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导出的镜像,导入时也没有名字
    [docker|podman] load -i <image>.tar
    

    不启动镜像,查看镜像内的文件

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