安装Podman:
在Ubuntu中,安装Podman的最简单方法是使用包管理器apt。首先,更新系统软件包列表:
sudo apt update
然后,安装podman:
sudo apt install podman
配置Podman环境:
Podman需要cgroup v2来管理容器,我们需要确保我们的系统已启用它。打开文件/etc/default/grub,并在GRUB_CMDLINE_LINUX_DEFAULT行中添加systemd.unified_cgroup_hierarchy=1:
sudo nano /etc/default/grub
GRUB_CMDLINE_LINUX_DEFAULT="quiet splash systemd.unified_cgroup_hierarchy=1"
更新GRUB配置:
sudo update-grub
重新启动系统:
sudo reboot
操作Podman:
创建一个新的容器:
podman run -it ubuntu /bin/bash
这将启动一个新的容器内的bash shell。
列出正在运行的容器:
podman ps
停止容器:
podman stop <容器ID>
删除容器:
podman rm <容器ID>
列出所有本地映像:
podman images
构建映像:
podman build -t myimage .
在容器内部运行命令:
podman exec <容器ID> <命令>
例如,在容器内部安装vim:
podman exec <容器ID> apt-get update && apt-get install -y vim
导出容器:
podman export <容器ID> > mycontainer.tar
导入容器:
podman import mycontainer.tar