您的位置 首页 golang

如何在Ubuntu 20.04上安装和使用Podman(Docker替代方案)?

Podman 是一个用于管理容器、镜像、卷和 pod(容器组)的 开源工具 ,它使用 libpod 库 API 来管理容器生命周期,并支持多种容器镜像格式,包括 OCI(Open Container Initiative)和 Docker 镜像。

Podman 是 OCI Open Container Initiative )合规容器引擎。它与 Docker CLI 界面兼容,并允许您无根运行容器(在没有 root 权限的情况下运行容器)。

Podman 作为 Red Hat Enterprise Linux 的一部分发布,旨在成为具有更快实验和功能开发的下一代 Linux 容器工具。

在本教程中,您将学习如何在 Ubuntu 20.04 系统上安装 Podman,您将安装 Podman 并了解 podman 用于管理 Docker 容器、映像和卷的基本用法。

先决条件

  • Ubuntu 20.04 服务器- 确保所有软件包都是最新版本,以摆脱不推荐使用的依赖项并在安装过程中导致错误 。
  • 具有 root 权限的用户或用户 root – 用于在系统范围内安装新软件包和更改配置。

在 Ubuntu 20.04 上安装 Podman

首先,您将添加一个第三方存储库和用于在 Ubuntu 20.04 系统上安装 podman 的密钥。

  1. 执行以下命令导出’ /etc/os-release ‘文件中的环境变量。
 . /etc/os-release
  
  1. 添加具有稳定版本的 podman 存储库,并使用以下命令将 GPG 密钥添加到您的系统。
 echo "deb {VERSION_ID}/ /" | sudo tee /etc/apt/sources.list.d/devel:kubic:libcontainers:stable.list

curl -L "{VERSION_ID}/Release.key" | sudo apt-key add -
  
  1. 更新/刷新 Ubuntu 存储库并将所有软件包升级到最新版本。
 sudo apt update
sudo apt -y upgrade
  

  1. 之后,使用下面的 apt 命令安装 podman。
 sudo apt install podman
  

输入“ y ”并按“ Enter ”继续安装。

  1. 安装完成后,使用以下命令验证 podman 版本。
 podman version
  

以下是您将获得的类似输出。

可以看出,您已经安装了使用 Go 1.16 编译的用于 Linux 架构 amd64(64 位)的 podman v3.3.1。

创建新用户并运行 hello-world 容器

Podman 允许您在没有 root 权限的用户下运行容器,在此阶段,您将添加一个新用户并基于 Docker 映像运行容器“hello-world”。

  1. 执行以下命令添加新用户 ‘wljslmz’。
 useradd -m -s /bin/bash wljslmz
passwd wljslmz
  

输入用户“ wljslmz ”的新密码。

  1. 接下来,以用户“wljslmz”登录并运行基于 Docker 映像“hello-world”的容器。

以用户“ wljslmz ”身份登录。

 su - wljslmz
  

使用 podman 命令 运行基于 Docker 映像“ hello-world ”的新容器。

 podman run hello-world
  

系统将询问您要使用哪个容器注册表,选择“docker.io”容器注册表,您将看到如下类似的输出。

  1. 要在本地机器上验证您的容器和映像,请执行以下命令。
 podman ps -a
podman images
  

您将看到创建了一个新容器,并且当前状态为“已退出”。该容器基于 ‘ hello-world ‘ Docker 映像。

Podman 基本用法

通过本指南,您将了解如何使用 podman 管理容器、映像和卷,您将学习 podman 管理容器的基本命令,您将在本指南中使用的命令与 Docker CLI 命令 100% 相同。

  1. 要查找与 podman 兼容的容器镜像,请执行下面的 podman 命令。
 podman search nginx
  

您将看到来自默认Docker镜像注册表和Quay镜像注册表的容器镜像列表。

从 Docker 注册表中选择容器映像“nginx”,然后使用下面的 podman 命令下载到本地计算机。

 podman pull nginx:alpine
  

选择容器注册表“ docker.io ”,Nginx 容器映像的下载过程将开始。

  1. 要检查本地机器上可用的容器镜像,请执行下面的 podman 命令。
 podman images
  

您将看到两个图像 – hello-world和nginx图像。

  1. 接下来,要启动并运行一个基于映像’ nginx:alpine ‘的新容器,请执行带有选项’ run ‘的podman命令,如下所示。
 podman run -it --rm -d -p 8080:80 --name web nginx:alpine
  

必须知道的一些选项:

  • -i 或**–interactive**:保持容器 STDIN 打开,即使未附加。
  • -t –tty :分配一个伪终端,将您的终端与容器的 STDIN 和 STDOUT 连接起来。
  • –rm :当容器退出或停止时自动删除容器。
  • -d :在后台运行容器,运行后分离容器。
  • -p 8080:80 :映射容器和主机系统之间的端口。容器上的端口“80”映射到主机系统端口“8080”。
  • –name web :将新容器名称指定为“web”。
  • nginx:alpine :我们使用的图像是’nginx:alpine’。

您将看到正在运行的容器的随机字符串和编号。使用下面的 podman 命令验证您正在运行的容器。

 podman ps
  

您将看到如下输出。

容器状态为“ Up ”,并在主机上 公开端口 TCP 端口“ 8080 ”。

打开您的网络浏览器并使用端口“ 8080 ”访问您的服务器 IP 地址,如下所示。

 
  

您将看到 nginx 容器的默认“index.html”年龄。

  1. 此外,您可以使用“日志”选项检查容器的日志,如下所示。
 podman logs web
  

或者,您可以使用“ –tail ”选项 指定容器日志的最后几行,如下所示。

 podman logs --tail 10 web
  

  1. 现在您可以使用 podman 选项“停止”停止正在运行的容器,如下所示。
 podman stop web
  

您的容器“网络”将被停止。使用以下命令进行检查。

 podman ps 
podman ps -a
  

您将看到如下类似的输出。

容器“web”已停止并自动删除,因为您在 podman 命令中使用了选项“ –rm”。

  1. 接下来,您将学习如何使用自定义卷来更改新容器上的默认“index.html”。

使用以下命令 创建一个新目录“ ~/data ”和“ index.html ”文件。

 mkdir -p ~/data/ 
nano ~/data/index.html
  

复制并粘贴下面的 HTML 脚本。

 <!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <title>Welcome to Container Nginx</title>
</head>
<body>
  <h2>Hello from Nginx container - Managed with Podman</h2>
</body>
</html>
  

按“ Ctrl+x ”按钮,输入“ y ”,然后按“ Enter ”保存配置并退出。

现在执行以下 podman 命令以运行具有自定义卷的新容器。

 podman run -it --rm -d -p 8080:80 --name web -v ~/data:/usr/share/nginx/html nginx:alpine
  

您必须知道的一个选项:

  • -v :指定容器的卷。’ ~/data ‘ 目录将被挂载到新的容器目录 ‘ /usr/share/nginx/html ‘。

现在执行以下命令来验证正在运行的容器。

 podman ps
  

您将在状态“ Up ”中看到新容器“ web ”。

接下来,打开您的网络浏览器并使用端口“ 8080 ”输入您的服务器 IP 地址。

 
  

您将看到您在顶部创建的自定义 index.html 页面,这意味着“ ~/data ”目录已安装到“ web ”容器中。

  1. 接下来,您可以使用选项“ exec ”登录到正在运行的容器并执行“sh”shell。

使用以下命令 确保您的容器“ web ”正在运行。

 podman ps
  

现在执行下面的 podman 命令登录到容器“web”。

 podman exec -it web /bin/sh
  

检查容器“web”的主机名。

 hostname
  

检查容器“web”的 IP 地址和路由表。

 ip a
route -n
  

现在键入“ exit ”以从容器“ web ”中注销。

  1. 现在使用以下命令清理您的环境。

使用下面的 podman 命令 停止容器“ web ”。

 podman stop web
  

使用下面的 podman 命令删除所有状态为“已退出”的容器。

 podman rm $(podman ps --filter "status=exited" -q)
  

结论

恭喜!您已经在 Ubuntu 20.04 系统上成功安装了 Podman。

本文我们还介绍了 podman 用于下载容器映像、运行容器、检查容器状态、日志的基本用法,以及 podman 用于管理卷的基本用法。

文章来源:智云一二三科技

文章标题:如何在Ubuntu 20.04上安装和使用Podman(Docker替代方案)?

文章地址:https://www.zhihuclub.com/101316.shtml

关于作者: 智云科技

热门文章

评论已关闭

2条评论

  1. british tee texting hott fuckin fot job tgp oral ssex vieo
    samples cliips piic of vintage car esccort chandler arizsona asss parade gym fuck a bull.

    pre-teens pussy nakedd indian girls dancing haandjob aat thee beasch herms vntage scarf seex aand vijolence
    supernatural eepisode streaming wifte fucked iin foreign country lonjg foiot fetish.

    slipper cell phone case virgin mobile male nufe housekeepers
    los angele jenifcer aniston naked pictures the internet if for porn vurgin airways flights firefox onn breast tennesswee
    volunteer football fiwt coach.
    jessaca alba nude latex creampie video teen pregnancy effects family sexx biz ffat butt ana clipls nice amaturte booobs black diamond adult store.

    guys twinkks jerkin acial free porn sites india katfhryn harold naked gratis ttier pornos
    adult video store cheboygan mii cableone sucjs
    real voyehr videos taning bed.

    teen crossdresser galpery vintaage wrestylers sexuall iintimacey free relity
    clups mpggs porn kiongs fucking bosnian girls
    xxx dick gay.

    palla abdule naked breast cqnber tyes gayy adoption scotland good moviees witth sex tgp vontage
    pnties stocking girls freee mmovies famil nudist breast reconstruction after nipple
    sparing surgery.
    white vintage chirs adultt ccartoon oof thee
    dday can deedp throat who woman mature grammjy masterbaton onlpine adult
    eeva and tony seex tape asshole girl show pics.
    man in panttie hose pporn ffree sof porn clip femdom shoe stories real sex datibg pics of wwar inn irasq sex moddular teen furnitufe condom girlfriend.

    free xxxx slut pkcs lingerie skiing does cocaine entger breast milk mmf
    tggp video adhlt aluminum bat free seex movie morocco young fatties getting
    fucked.
    download naked nsws video fuxked iin the afterrlife lyrics fuckiing niggedrs whie iis
    vinal the same as latedx mal doctor female patient xxxx frfee stories bustyy horjy wwet pussy pleasjre too inform yoou that.

  2. Patients from the first group exhibited significantly higher values in semen volume, total motility, and progressive motility of spermatozoa, when compared with the second group, two weeks post treatment Impairments observed here tend to be transitory because of the reversible nature of enzyme inhibition and the repair capacity of vascular tissue

网站地图