在 Podman 中运行一个 Linux 虚拟机

系统 Linux
使用 Podman Machine 创建一个基本的 Fedora CoreOS 虚拟机来使用容器和容器化工作负载。

[[414498]]

使用 Podman Machine 创建一个基本的 Fedora CoreOS 虚拟机来使用容器和容器化工作负载。

Fedora CoreOS 是一个自动更新、最小化的基于 rpm-ostree 的操作系统,用于安全地、大规模地运行容器化工作负载。

Podman “是一个用于管理容器和镜像、挂载到这些容器中的卷,以及由这些容器组组成的吊舱的工具。Podman 基于 libpod,它是一个容器生命周期管理库”。

当你使用 Podman Machine 时,神奇的事情发生了,它可以帮助你创建一个基本的 Fedora CoreOS 虚拟机(VM)来使用容器和容器化工作负载。

开始使用 Podman Machine

第一步是安装 Podman。如果你已经安装了最新版本的 Podman,你可以跳过这个步骤。在我的 Fedora 34 机器上,我用以下方式安装 Podman:

  1. $ sudo dnf install podman

我使用的是 podman-3.2.2-1.fc34.x86_64。

初始化 Fedora CoreOS

Podman 安装完成后,用以下方法初始化它:

  1. podman machine init vm2
  2. Downloading VM image: fedora-coreos-34.20210626.1.0-qemu.x86_64.qcow2.xz: done
  3. Extracting compressed file

这个命令创建了 vm2,并下载了 .xz 格式的 Fedora CoreOS 的 qcow2 文件并将其解压。

列出你的虚拟机

了解你的虚拟机和它们的状态是很重要的,list 命令可以帮助你做到这一点。下面的例子显示了我所有的虚拟机的名称,它们被创建的日期,以及它们最后一次启动的时间:

  1. podman machine list
  2. NAME VM TYPE CREATED LAST UP
  3. podman-machine-default* qemu 6 days ago Currently running
  4. vm2 qemu 11 minutes ago 11 minutes ago

启动一个虚拟机

要启动一个虚拟机,请运行:

  1. podman machine start
  2. Waiting for VM ...

SSH 到虚拟机

你可以使用 SSH 来访问你的虚拟机,并使用它来运行工作负载,而没有任何麻烦的设置:

  1. podman machine ssh
  2. Connecting to vm podman-machine-default. To close connection, use `~.` or `exit`
  3. Fedora CoreOS 34.20210611.1.0
  4. Tracker: https://github.com/coreos/fedora-coreos-tracker
  5. Discuss: https://discussion.fedoraproject.org/c/server/coreos/
  6. Last login: Wed Jun 23 13:23:36 2021 from 10.0.2.2
  7. [core@localhost ~]$ uname -a
  8. Linux localhost 5.12.9-300.fc34.x86_64 #1 SMP Thu Jun 3 13:51:40 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux
  9. [core@localhost ~]$

目前,Podman 只支持一次运行一个虚拟机。

停止你的虚拟机

要停止运行中的虚拟机,请使用 stop 命令:

  1. podman machine stop
  2.  
  3. [core@localhost ~]$ Connection to localhost closed by remote host.
  4. Connection to localhost closed.
  5. Error: exit status 255

我希望这能帮助你开始使用 Podman Machine。 

责任编辑:庞桂玉 来源: Linux中国
相关推荐

2022-05-04 11:07:32

虚拟机Linux

2022-04-27 10:51:00

PythonMLCubePodman

2022-02-15 14:08:32

虚拟机Wasm浏览器

2023-11-17 14:06:43

2022-07-04 12:26:00

云原生开源

2022-01-26 16:30:47

代码虚拟机Linux

2021-03-10 07:52:58

虚拟机程序VMware

2012-05-04 11:28:41

虚拟化KVM高性能

2023-09-25 08:19:37

LinuxVirtualBox虚拟机

2019-08-26 19:03:58

2018-06-22 10:30:56

C语言虚拟机编译器

2011-05-12 11:35:32

Oracle VM V虚拟机

2010-02-24 10:49:11

Python运行环境

2022-01-18 17:57:21

PodmanLinux容器

2009-05-20 19:33:34

Vista虚拟机Linux

2010-03-10 08:59:25

Linux添加硬盘

2012-07-03 13:15:00

vSphere虚拟机存储

2015-11-25 13:48:18

Linux虚拟机技巧

2013-12-09 15:35:44

Docker虚拟机

2020-01-17 10:52:37

无服务器容器技术
点赞
收藏

51CTO技术栈公众号