Linux Shell 实现一键部署podman

Linux Shell 实现一键部署podman_第1张图片

podman 介绍

使用 Podman 管理容器、Pod 和映像。从本地环境中无缝使用容器和 Kubernetes,Podman 提供与 Docker 非常相似的功能,它不需要在你的系统上运行任何守护进程,并且它也可以在没有 root 权限的情况下运行。

Podman 可以管理和运行任何符合 OCI(Open Container Initiative)规范的容器和容器镜像。Podman 提供了一个与 Docker 兼容的命令行前端来管理 Docker 镜像。

podman download

podman podman 文档 gitlab开源 podman ubuntu repo
download 参考 参考 参考

创建一键部署脚本

  • 主要用于安装Podman容器引擎。脚本首先检查操作系统的版本,并根据不同的操作系统版本选择相应的安装方法。脚本支持CentOS、Red Hat、Oracle Linux、Rocky Linux、AlmaLinux、Ubuntu、Debian、Fedora和SUSE等多个发行版。
  • 使用yum包管理器安装Podman及其插件,并配置registries.conf文件。对于Ubuntu和Debian,使用apt包管理器安装Podman及其插件,并配置registries.conf文件。对于Fedora,使用dnf包管理器安装Podman及其插件。对于SUSE,使用zypper包管理器安装Podman及其插件。
  • podman --version | awk '{print $3}' #podman版本获取
  • podman-compose --version 2>&1 | awk 'NR==1{print $3}' #podman-compose 版本获取
  • podman-compose --version 2>&1 | head -n1 | awk '{print $NF}' #podman-compose 版本获取
  • podman --help 命令使用参考
vi /podman_install.sh
#!/bin/bash
# -*- coding: utf-8 -*-
# Author: CIASM
# update 2023/09/18

< /dev/null; then
#if [ ! -d "/usr/bin/podman" ]; then
  echo -e "\033[32m Installing podman for $OS $VERSION...\033[0m"
  case $VERSION in
 
# CentOS/RedHat/oracle 7 install
    7.?)
	echo Installing basics...
	install_centos_podman
   ;;

# CentOS/RedHat/oracle/RockLinux/AlmaLinux 8 install 
    8.?)
	echo Installing basics...
	install_centos_podman
   ;;

# CentOS/RedHat/oracle/RockLinux/AlmaLinux 9 install
   9.?) 
	echo Installing basics...
	install_centos_podman
   ;;
   
  # ubuntu 20.04 Linux install
   20.04)
	echo Installing basics...
	echo "deb https://download.opensuse.org/repositories/devel:/kubic:/libcontainers:/stable/xUbuntu_20.04/ /" | sudo tee /etc/apt/sources.list.d/devel:kubic:libcontainers:stable.list
	curl -L "https://download.opensuse.org/repositories/devel:/kubic:/libcontainers:/stable/xUbuntu_20.04/Release.key" | sudo apt-key add -
	apt update
	install_ubuntu_podman
   ;;

 # ubuntu 21 Linux install
   21.04|21.10)
	echo Installing basics...
	echo "deb https://download.opensuse.org/repositories/devel:/kubic:/libcontainers:/stable/xUbuntu_21.04/ /" | sudo tee /etc/apt/sources.list.d/devel:kubic:libcontainers:stable.list
	curl -L "https://download.opensuse.org/repositories/devel:/kubic:/libcontainers:/stable/xUbuntu_21.04/Release.key" | sudo apt-key add -
	apt update
	install_ubuntu_podman
   ;;

 # ubuntu 22 Linux install
   22.04)
	echo Installing basics...
	echo "deb https://download.opensuse.org/repositories/devel:/kubic:/libcontainers:/stable/xUbuntu_22.04/ /" | sudo tee /etc/apt/sources.list.d/devel:kubic:libcontainers:stable.list
	curl -L "https://download.opensuse.org/repositories/devel:/kubic:/libcontainers:/stable/xUbuntu_22.04/Release.key" | sudo apt-key add -
	apt update
	install_ubuntu_podman
   ;;
  
  # Debian 10, 11 , 12
  10)
   echo Installing basics...
   	echo Installing basics...
	echo "deb https://download.opensuse.org/repositories/devel:/kubic:/libcontainers:/stable/Debian_10/ /" | sudo tee /etc/apt/sources.list.d/devel:kubic:libcontainers:stable.list
	curl -L "https://download.opensuse.org/repositories/devel:/kubic:/libcontainers:/stable/Debian_10/Release.key" | sudo apt-key add -
	apt update
	install_ubuntu_podman
   ;;
   
   11)
   echo Installing basics...
   	echo Installing basics...
	echo "deb https://download.opensuse.org/repositories/devel:/kubic:/libcontainers:/stable/Debian_11/ /" | sudo tee /etc/apt/sources.list.d/devel:kubic:libcontainers:stable.list
	curl -L "https://download.opensuse.org/repositories/devel:/kubic:/libcontainers:/stable/Debian_11/Release.key" | sudo apt-key add -
	apt update
	install_ubuntu_podman
   ;;
   
  12)
   echo Installing basics...
   	echo Installing basics...
	echo "deb https://download.opensuse.org/repositories/devel:/kubic:/libcontainers:/stable/Debian_12/ /" | sudo tee /etc/apt/sources.list.d/devel:kubic:libcontainers:stable.list
	curl -L "https://download.opensuse.org/repositories/devel:/kubic:/libcontainers:/stable/Debian_12/Release.key" | sudo apt-key add -
	apt update
	install_ubuntu_podman
   ;;
   
   
  # Fedora 31,32,33
  36|37|38)
   	echo Installing basics...
   install_centos_podman
   ;;

  # SUSE 12 install
  12.?)
	echo Installing  basics...
	sudo SUSEConnect -p sle-sdk/12.4/x86_64
	install_suse_podman
   ;;

  # SUSE 15 install
  15.?)
	echo Installing  basics...
	sudo SUSEConnect -p sle-sdk/15.3/x86_64
	install_suse_podman
   ;;
    *)
	
    echo -e "\033[31m Unsupported $OS $VERSION...\033[0m" 
    exit 1
    ;;
esac
	
    echo -e "\033[32m podman for $OS $VERSION successfully installed...\033[0m"
else
    echo -e "\033[33m podman for $OS $VERSION already installed...\033[0m"
fi

}

install_centos_podman() {
echo "install podman"
yum -y install podman podman-plugins podman-docker python3
pip3 install podman-compose

#registries.conf add config
cat >>/etc/containers/registries.conf<&1 | head -n1 | awk '{print $NF}'
}

install_ubuntu_podman() {
echo "install podman"
apt -y install podman podman-plugins python3 python3-pip
pip3 install podman-compose

cat >>/etc/containers/registries.conf<&1 | head -n1 | awk '{print $NF}'

}

install_suse_podman() {
echo "install podman"
sudo zypper in -y podman net-tools vim wget net-tools
}

main (){
	install_basics
}

main

执行一键安装podman 

sh /podman_install.sh

你可能感兴趣的:(Linux-Shell,linux,podman,运维)