如何在Ubuntu上安装Podman

时间:2020-02-23 14:31:36  来源:igfitidea点击:

如何在Ubuntu上安装Podman? Podman(Pod Manager)是用于创建和维护容器的工具。它是libpod库的一部分。红帽团队一直在研究一套无需守护程序即可运行容器的工具。我们知道没有Docker Engine守护程序就无法运行Docker容器吗?

以下工具集可以协同工作,以在没有一直运行的守护进程的情况下增强容器的使用。 directory.Podman用于运行不需要守护程序的容器。

Buildahs命令复制在Dockerfile中找到的所有命令。 Buildah容器只是为了允许将内容添加回容器镜像而创建的。

如何使用Buildah构建OCI和Docker容器镜像

Podman为我们提供维护和修改OCI图像所需的所有命令和功能,例如"拉"和"标记"。它还允许我们创建,运行和维护从这些镜像创建的容器。

如何在Ubuntu上安装Podman

podman软件包位于PPA存储库中,需要在安装之前添加。在Ubuntu机器上启动新的终端会话,然后运行以下命令。

. /etc/os-release
echo "deb https://download.opensuse.org/repositories/devel:/kubic:/libcontainers:/stable/xUbuntu_${VERSION_ID}//" | sudo tee /etc/apt/sources.list.d/devel:kubic:libcontainers:stable.list
curl -L https://download.opensuse.org/repositories/devel:/kubic:/libcontainers:/stable/xUbuntu_${VERSION_ID}/Release.key | sudo apt-key add 

添加存储库后,继续安装Podman。

sudo apt update
sudo apt -y install podman

安装后,我们可以显示有关主机,当前存储状态和podman的构建的信息。

$podman  info
podman  info
host:
  arch: amd64
  buildahVersion: 1.14.9
  cgroupVersion: v1
  conmon:
    package: 'conmon: /usr/libexec/podman/conmon'
    path: /usr/libexec/podman/conmon
    version: 'conmon version 2.0.16, commit: '
  cpus: 2
  distribution:
    distribution: ubuntu
    version: "20.04"
  eventLogger: file
  hostname: ceph-admin
  idMappings:
    gidmap: null
    uidmap: null
  kernel: 5.4.0-33-generic
  memFree: 7047921664
  memTotal: 8149680128
  ociRuntime:
    name: runc
    package: 'runc: /usr/sbin/runc'
    path: /usr/sbin/runc
    version: 'runc version spec: 1.0.1-dev'
  os: linux
  rootless: false
  slirp4netns:
    executable: ""
    package: ""
    version: ""
  swapFree: 0
  swapTotal: 0
  uptime: 1h 34m 54.9s (Approximately 0.04 days)
registries:
  search:
  - docker.io
  - quay.io
store:
  configFile: /etc/containers/storage.conf
  containerStore:
    number: 0
    paused: 0
    running: 0
    stopped: 0
  graphDriverName: overlay
  graphOptions: {}
  graphRoot: /var/lib/containers/storage
  graphStatus:
    Backing Filesystem: extfs
    Native Overlay Diff: "true"
    Supports d_type: "true"
    Using metacopy: "false"
  imageStore:
    number: 0
  runRoot: /var/run/containers/storage
  volumePath: /var/lib/containers/storage/volumes

在Ubuntu上测试Podman安装

拉高山docker图片。

$podman pull alpine
Trying to pull docker.io/library/alpine…Getting image source signatures
Copying blob 8e402f1a9c57: 2.63 MiB/2.63 MiB [=======================] 5s
Copying config 5cb3aa00f899: 1.48 KiB/1.48 KiB [=====================] 0s
Writing manifest to image destination
Storing signatures
5cb3aa00f89934411ffba5c063a9bc98ace875d8f92e77d0029543d9f2ef4ad0

列出下载的图像

$podman  images
REPOSITORY                      TAG      IMAGE ID       CREATED        SIZE
docker.io/library/alpine        latest   5cb3aa00f899   3 days ago     5.79 MB
docker.io/library/hello-world   latest   fce289e99eb9   2 months ago   5.62 kB

Podmans本地存储库位于/var/lib/containers中。

使用类似于docker的命令命令选项运行容器。

$podman  run -it  --rm docker.io/library/alpine /bin/sh
/# apk update
fetch http://dl-cdn.alpinelinux.org/alpine/v3.9/main/x86_64/APKINDEX.tar.gz
fetch http://dl-cdn.alpinelinux.org/alpine/v3.9/community/x86_64/APKINDEX.tar.gz
v3.9.2-1-g592d872fb8 [http://dl-cdn.alpinelinux.org/alpine/v3.9/main]
v3.9.2-2-ge7dc3349a9 [http://dl-cdn.alpinelinux.org/alpine/v3.9/community]
OK: 9754 distinct packages available

/# apk add vim
 (1/5) Installing lua5.3-libs (5.3.5-r1)
 (2/5) Installing ncurses-terminfo-base (6.1_p20190105-r0)
 (3/5) Installing ncurses-terminfo (6.1_p20190105-r0)
 (4/5) Installing ncurses-libs (6.1_p20190105-r0)
 (5/5) Installing vim (8.1.0630-r0)
 Executing busybox-1.29.3-r10.trigger
 OK: 40 MiB in 19 packages
/# exit

显示正在运行的容器。

$podman ls
CONTAINER ID  IMAGE                            COMMAND  CREATED        STATUS            PORTS  NAMES
1eb35f1b7de8  docker.io/library/alpine:latest  /bin/sh  4 seconds ago  Up 4 seconds ago         pedantic_roentgen
ec9c5b12db46  docker.io/library/alpine:latest  /bin/sh  5 minutes ago  Up 5 minutes ago         ecstatic_wiles

有关更多用法,请查看:如何使用Podman和Libpod运行Docker容器

要设置私人注册表,请结帐:

使用Podman设置Docker容器注册表并让SSL加密