ubuntu podman相关
前言
记录podman的安装、配置以及一些常用操作,会不定时更新;
正文
1. podman 安装以及配置
ubuntu 安装 podman
sudo apt update
sudo apt install podman -y
podman配置国内镜像源
cd /etc/containers/
mv registries.conf registries.conf-bak
touch registries.conf
使用vim等编辑器编辑registries.conf:
unqualified-search-registries = ["docker.io"]
[[registry]]
prefix = "docker.io"
insecure = false
blocked = false
location = "docker.io"
[[registry.mirror]]
# location = "j3m2itm3.mirror.aliyuncs.com"
location = "docker.mirrors.ustc.edu.cn"
配置日志大小
cd /etc/containers/
touch containers.conf
# 编辑containers.conf内容如下 (日志大小10M,根据需求修改)
[containers]
log_size_max=10485760
2. podman常用指令
podman指令兼容docker指令,镜像也能用docker镜像;
可以使用:
podman --help
或
podman 二级指令 --help(如 podman run --help)查询帮助。
# - 搜索镜像,如 openresty
podman search openresty
# - 安装镜像
podman pull openresty/openresty
podman pull openresty/openresty:alpine # 指定镜像TAG
podman pull openresty/openresty:latest # 指定镜像TAG
# - 运行镜像
podman run -idt -p 12123:80 -v \
/opt/openresty/nginx/conf:/usr/local/openresty/nginx/conf:Z
--name openresty --privileged=true openresty/openresty:alpine
# -i 允许对容器进行交互
# -d 后台运行 不会进入容器
# -t 在新容器内指定一个伪终端或终端
# -p 建立端口映射,主机(宿主)端口:容器端口
# -v 文件存储,左侧为映射到本地:右侧为容器内文件夹,防止镜像过大,迁移困难
# --privileged 给容器权限
# --name 给启动的容器命名
# --net=host,这种是允许虚拟机和宿主机使用同一套网络,不能和-p同时使用,否则会报错:Port mappings have been discarded as one of the Host, Container, Pod, and None network modes are in use
# 查看运行的容器
podman ps -a
podman ps -f + 过滤条件扩展
#podman ps -f ancestor= before= exited= health= id= label= name= network= since= status= until= volume=
# 进入容器(后面可以根据实际选用sh或bash)
podman exec -it 容器id sh
podman exec -it 容器name sh
# 停止容器
podman stop 容器id
podman stop 容器name
# 删除容器
podman rm 容器id
podman rm 容器name
# 删除镜像
podman rmi 镜像名称
根据关键词进入容器:
enter_container.sh
#!/bin/bash
container_keyword=$1
function Usage()
{
echo -e "Usage: $0 <container_keyword>"
exit 0
}
if [[ $container_keyword == "" ]];then
Usage
fi
# find container id
container_id=`podman ps -a|grep $container_keyword|awk -F' ' '{print $1}'`
if [[ $container_id == "" ]];then
echo "not find container by keyword $container_keyword"
exit 0
fi
# enter container
podman exec -it $container_id bash
if [[ $? != 0 ]];then
podman exec -it $container_id sh
fi
停止所有容器:
stop_all.sh
#!/bin/bash
podman stop $(podman ps -a|grep -v CONTAINER|awk -F ' ' '{print $1}'|xargs)
删除所有已经停止的容器:
rm_all.sh
#!/bin/bash
podman rm $(podman ps -a|grep Exited |awk -F ' ' '{print $1}'|xargs)
参考
[1]. podman的配置以及命令详解;
[2]. Ubuntu安装podman;
[3]. 【Docker】docker介绍及podman使用命令;
[4]. docker run 命令详解(新手入门必备)
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· 单元测试从入门到精通
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 上周热点回顾(3.3-3.9)
· winform 绘制太阳,地球,月球 运作规律