温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

在Fedora如何使用Podman

发布时间:2022-02-18 14:29:52 来源:亿速云 阅读:145 作者:小新 栏目:开发技术

这篇文章主要为大家展示了“在Fedora如何使用Podman”,内容简而易懂,条理清晰,希望能够帮助大家解决疑惑,下面让小编带领大家一起研究并学习一下“在Fedora如何使用Podman”这篇文章吧。

Podman 是 Libpod 的一部分,它的定义可以简单用这个命令表示:alias docker=podman,Libpod 是一个创建容器 pod 的工具和库,它包含 pod 管理工具 Podman,Podman 管理 pod、容器、容器镜像和容器卷。

在Fedora如何使用Podman

安装 Podman

Podman 的命令就与 docker 相同,如果你已经安装了 Docker,只需在终端输入 alias docker=podman。

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

sudo dnf install podman

对于 Fedora silverblue 用户,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");
});

你可以从 这里 下载源代码。

创建 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

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

停止和删除容器

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

podman ps -a
podman stop

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

podman rmi

以上是“在Fedora如何使用Podman”这篇文章的所有内容,感谢各位的阅读!相信大家都有了一定的了解,希望分享的内容对大家有所帮助,如果还想学习更多知识,欢迎关注亿速云行业资讯频道!

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI