如何在 Fedora 上使用 Podman
Podman 容器
![](/data/attachment/album/202107/25/071145k1kbri7ei0ekk18p.jpg)


[Podman](https://podman.io/) 是一个无守护程序的容器引擎，用于在你的 Linux 系统上开发、管理和运行 OCI 容器。在这篇文章中，我们将介绍 Podman 以及如何用 nodejs 构建一个小型应用来使用它。该应用将是非常简单和干净的。


### 安装 Podman


Podman 的命令就与 [docker](https://www.docker.com/) 相同，如果你已经安装了 Docker，只需在终端输入 `alias docker=podman`。


在 Fedora 中，Podman 是默认安装的。但是如果你因为任何原因没有安装，你可以用下面的命令安装它：



```
sudo dnf install podman

```

对于 Fedora [silverblue](https://silverblue.fedoraproject.org/) 用户，Podman 已经安装在你的操作系统中了。


安装后，运行 “hello world” 镜像，以确保一切正常：



```
podman pull hello-world
podman run hello-world

```

如果一切运行良好，你将在终端看到以下输出：



```
Hello from Docker!
This message shows that your installation appears to be working correctly.
 To generate this message, Docker took the following steps:
  1.The Docker client contacted the Docker daemon.
  2.The Docker daemon pulled the "hello-world" image from the Docker Hub. (amd64)
  3.The Docker daemon created a new container from that image which runs the executable that produces the output you are currently reading.
  4.The Docker daemon streamed that output to the Docker client, which sent it to your terminal.
 To try something more ambitious, you can run an Ubuntu container with:
  $ docker run -it ubuntu bash
 Share images, automate workflows, and more with a free Docker ID:
  https://hub.docker.com/
 For more examples and ideas, visit:
  https://docs.docker.com/get-started/

```

### 简单的 Nodejs 应用


首先，我们将创建一个文件夹 `webapp`，在终端输入以下命令：



```
mkdir webapp && cd webapp

```

现在创建文件 `package.json`，该文件包括项目运行所需的所有依赖项。在文件 `package.json` 中复制以下代码：



```
{
       "dependencies": {
               "express": "*"
       },
       "scripts": {
               "start": "node index.js"
       }
}

```

创建文件 `index.js`，并在其中添加以下代码：



```
const express = require('express')

const app = express();

app.get('/', (req, res)=> {
       res.send("Hello World!")
});
app.listen(8081, () => {
       console.log("Listing on port 8080");
});

```

你可以从 [这里](https://github.com/YazanALMonshed/webapp) 下载源代码。


### 创建 Dockerfile


首先，创建一个名为 `Dockerfile` 的文件，并确保第一个字符是大写，而不是小写，然后在那里添加以下代码：



```
FROM node:alpine
WORKDIR usr/app
COPY ./ ./
RUN npm install
CMD ["npm", "start"]

```

确保你在 `webapp` 文件夹内，然后显示镜像，然后输入以下命令：



```
podman build .

```

确保加了 `.`。镜像将在你的机器上创建，你可以用以下命令显示它：



```
podman images

```

最后一步是输入以下命令在容器中运行该镜像：



```
podman run -p 8080:8080 <image-name>

```

现在在你的浏览器中打开 `localhost:8080`，你会看到你的应用已经工作。


### 停止和删除容器


使用 `CTRL-C` 退出容器，你可以使用容器 ID 来删除容器。获取 ID 并使用这些命令停止容器：



```
podman ps -a
podman stop <container_id>

```

你可以使用以下命令从你的机器上删除镜像：



```
podman rmi <image_id>

```

在 [官方网站](https://podman.io/) 上阅读更多关于 Podman 和它如何工作的信息。




---


via: <https://fedoramagazine.org/getting-started-with-podman-in-fedora/>


作者：[Yazan Monshed](https://fedoramagazine.org/author/yazanalmonshed/) 选题：[lujun9972](https://github.com/lujun9972) 译者：[geekpi](https://github.com/geekpi) 校对：[wxy](https://github.com/wxy)


本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译，[Linux中国](https://linux.cn/) 荣誉推出


OK
[Podman](https://podman.io/) is a daemonless container engine for developing, managing, and running OCI Containers on your Linux System. In this article, we will introduce podman and how to use it with a small application build using nodejs. The app will be very simple and clean.

## Install Podman

Podman command is the same as [docker](https://www.docker.com/) just type in your terminal **alias docker=podman** if you have docker already installed

Podman is installed by default in Fedora Linux. But if you don’t have it for any reason, you can install it using the following command:

sudo dnf install podman

For fedora [silverblue](https://silverblue.fedoraproject.org/) users, podman is already installed in your OS.

After installation, run the hello world image to ensure everything is working:

podman pull hello-world podman run hello-world

If everything is working well you will see the following output in your terminal:

Hello from Docker! This message shows that your installation appears to be working correctly. To generate this message, Docker took the following steps: 1.The Docker client contacted the Docker daemon. 2.The Docker daemon pulled the "hello-world" image from the Docker Hub. (amd64) 3.The Docker daemon created a new container from that image which runs the executable that produces the output you are currently reading. 4.The Docker daemon streamed that output to the Docker client, which sent it to your terminal. To try something more ambitious, you can run an Ubuntu container with: $ docker run -it ubuntu bash Share images, automate workflows, and more with a free Docker ID: https://hub.docker.com/ For more examples and ideas, visit: https://docs.docker.com/get-started/

## Simple Nodejs App

First, we will create a folder **webapp** , type the following command in your terminal

mkdir webapp && cd webapp

Now create the file** ***package.json* This file includes all the dependencies that the project needs to work well. Copy the following code inside the file *package.json .*

{ "dependencies": { "express": "*" }, "scripts": { "start": "node index.js" } }

Create the file *index.js* and add the following code there:

const express = require('express') const app = express(); app.get('/', (req, res)=> { res.send("Hello World!") }); app.listen(8080, () => { console.log("Listing on port 8080"); });

You can download source code from [here](https://github.com/YazanALMonshed/webapp).

## Create Dockerfile

First of all, create a file called *Dockerfile* and make sure the first character is a capital, NOT lower case, then add the following code there:

FROM node:alpine WORKDIR usr/app COPY ./ ./ RUN npm install CMD ["npm", "start"]

Be sure you are inside the folder *webapp* then show the image and then type the following command:

podman build .

Make sure to add the **dot**. The image is created on your machine and you can show it using the following command:

podman images

The last step is to run the image inside a container by typing the following command:

podman run -p 8080:8080 <image-name>

Now open your browser in *localhost:8080 *and you will see that your app works.

## Stopping and Remove Container

To exit from the container use *CTRL-C.* You can remove the container by using the container id. Get the id and stop the container using these commands:

podman ps -a podman stop <container_id>

You can delete the images from your machine by using the following command:

podman rmi <image_id>

Read more about podman and how it works on the [official website](https://podman.io/)

## Stephen Snow

In the article you state that to run Podman as Docker do the following …

“just type in your terminal ‘alias docker=podman’ if you have docker already installed” Then you use Docker instead of Podman as can be seen by the output of the command.

## Piyush Agarwal

Exactly, from this article I didn’t get the difference between docker and podman. It seems like an alias.

## Stephen Snow

‘alias docker=podman’ Definitely is an alias. I was incorrect though, it does run Podman and not Docker, the original image pulled is from Docker and the content of the message from the container is docker oriented, so my misinterpretation.

## Edier

Thank you.

I was looking forward to install Moby (Docker) but thanks to your article I found out that Podman is lighter and more efficient. I will start my project with Podman instead. Thanks

## Stephen Snow

Good to see you are no longer considered spam!

## hammerhead corvette

Excellent article Yazan ! Can we create an image of Anaconda with the minimal Fedora install? The Docker Anaconda package is Python2.7 and has not been updated in a while, but it would be nice to have the latest Fedora supported Python and current Anaconda package instead.

## yongbin

following line looks wrong.

app.listen(8081, () => {

console.log(“Listing on port 8080”);

});

## Yazan Monshed

Thanks for the note, I’ll fix it.

## Gregory Bartholomew

Hi Yazan. You won’t be able to edit your article directly after publication, but you can reach an editor to request a correction by posting a comment on the article’s Kanban card.

Since you’ve already said that this should be corrected, I’ll go ahead and take care of this one. Thanks!

## Yazan Monshed

Great, Thanks Gregory!

## Ralf

Honestly, that’s a bit strange and an absolutely no-go for me.

You should think about whether it would make sense in your case to put the author of a text above the editors.

## Gregory Bartholomew

Well, what I said isn’t entirely accurate. If Yazan wanted to, he could become an editor for Fedora Magazine and then he would be able to edit post-publication articles. We still strive not to edit articles post-publication though. I’m not sure what the reasoning is behind that rule though. I think it might have been something to do with search engine optimization. There may have been other reasons.

## Ralf

Well then, congratulations on the promotion Yazan, and thanks for the explanation Gregory.

## Ralf Seidenschwang

I’m a bit fascinated about the whole ecosystem that has evolved over the years and that is no longer manageable from a singe person.

Virtualization is still in the enterprises, but the question is: How long? Will it vanish completely?

## Yazan Monshed

Well, good question. Virtualization does not conflict with containers, you can look to the containers as “the New way to Delivery the Software” which means the containers don’t compete with the virtualization. this is my perspective.

## Ralf

Well, I understand that they have not the same use case, but with OpenShift Virtualization for example, there is certainly some battle for customers between the Operator for the OpenShift product and Red Hat virtualization based on oVirt. Maintaining both environments would be expensive.

## Ralf

Thanks a lot. I haven’t much experience with Node.js or JavaScript, but I think you can’t remove images from the local store without first delete the container with the rm command.

I recommend the new book listed here -> https://www.keycloak.org/

Node.js examples are included. It introduces the user to some common simple programming design patterns.

Happy reading!

## Ben

Is podman compatible with Singularity (used dominantly in HPC/scientific computing over docker) ?