自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

如何在 Fedora 上使用 Podman

系統(tǒng) Linux
Podman 是一個無守護(hù)程序的容器引擎,用于在你的 Linux 系統(tǒng)上開發(fā)、管理和運行 OCI 容器。在這篇文章中,我們將介紹 Podman 以及如何用 nodejs 構(gòu)建一個小型應(yīng)用來使用它。該應(yīng)用將是非常簡單和干凈的。

Podman 是一個無守護(hù)程序的容器引擎,用于在你的 Linux 系統(tǒng)上開發(fā)、管理和運行 OCI 容器。在這篇文章中,我們將介紹 Podman 以及如何用 nodejs 構(gòu)建一個小型應(yīng)用來使用它。該應(yīng)用將是非常簡單和干凈的。

安裝 Podman

Podman 的命令就與 docker 相同,如果你已經(jīng)安裝了 Docker,只需在終端輸入 alias docker=podman

在 Fedora 中,Podman 是默認(rèn)安裝的。但是如果你因為任何原因沒有安裝,你可以用下面的命令安裝它:

  1. sudo dnf install podman

對于 Fedora silverblue 用戶,Podman 已經(jīng)安裝在你的操作系統(tǒng)中了。

安裝后,運行 “hello world” 鏡像,以確保一切正常:

  1. podman pull hello-world
  2. podman run hello-world

如果一切運行良好,你將在終端看到以下輸出:

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

簡單的 Nodejs 應(yīng)用

首先,我們將創(chuàng)建一個文件夾 webapp,在終端輸入以下命令:

  1. mkdir webapp && cd webapp

現(xiàn)在創(chuàng)建文件 package.json,該文件包括項目運行所需的所有依賴項。在文件 package.json 中復(fù)制以下代碼:

  1. {
  2. "dependencies": {
  3. "express": "*"
  4. },
  5. "scripts": {
  6. "start": "node index.js"
  7. }
  8. }

創(chuàng)建文件 index.js,并在其中添加以下代碼:

  1. const express = require('express')
  2.  
  3. const app = express();
  4.  
  5. app.get('/', (req, res)=> {
  6. res.send("Hello World!")
  7. });
  8. app.listen(8081, () => {
  9. console.log("Listing on port 8080");
  10. });

你可以從 這里 下載源代碼。

創(chuàng)建 Dockerfile

首先,創(chuàng)建一個名為 Dockerfile 的文件,并確保第一個字符是大寫,而不是小寫,然后在那里添加以下代碼:

  1. FROM node:alpine
  2. WORKDIR usr/app
  3. COPY ./ ./
  4. RUN npm install
  5. CMD ["npm", "start"]

確保你在 webapp 文件夾內(nèi),然后顯示鏡像,然后輸入以下命令:

  1. podman build .

確保加了 .。鏡像將在你的機器上創(chuàng)建,你可以用以下命令顯示它:

  1. podman images

最后一步是輸入以下命令在容器中運行該鏡像:

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

現(xiàn)在在你的瀏覽器中打開 localhost:8080,你會看到你的應(yīng)用已經(jīng)工作。

停止和刪除容器

使用 CTRL-C 退出容器,你可以使用容器 ID 來刪除容器。獲取 ID 并使用這些命令停止容器:

  1. podman ps -a
  2. podman stop <container_id>

你可以使用以下命令從你的機器上刪除鏡像:

  1. podman rmi <image_id>

在 官方網(wǎng)站 上閱讀更多關(guān)于 Podman 和它如何工作的信息。 

責(zé)任編輯:龐桂玉 來源: Linux中國
相關(guān)推薦

2022-09-22 16:21:43

開源GUI 應(yīng)用

2021-11-28 06:33:24

Discord消息收發(fā)應(yīng)用 Linux

2023-11-26 16:23:16

FedoraVSCodium

2020-12-28 06:44:45

FedoraLinux RPM文件

2021-08-18 11:19:25

FedoraLinuxJava

2018-05-14 08:36:06

JavaFedoraOpenJDK

2018-06-11 09:55:09

LinuxFedorazsh

2020-11-26 10:25:09

FedoraPodmanLinux

2021-03-14 13:00:36

FedoraPoetry Python

2015-06-01 12:19:03

FedoraCentOSSamba

2020-03-02 18:16:12

FedoraLinuxMongoDB

2023-08-24 10:24:54

GitLabPodman

2017-04-11 13:20:06

CentOSRHELFedora

2021-11-05 08:00:00

數(shù)據(jù)庫PostgreSQL開源

2014-10-11 11:30:43

CentOSDocker

2020-06-15 18:20:37

Fedora電子書開源

2019-01-07 09:50:06

Linuxtarball命令

2019-11-26 16:58:51

Linuxpkgsrc

2023-01-17 07:40:59

LinuxAppImage應(yīng)用程序

2017-04-24 18:10:27

DrupalCentOSFedora
點贊
收藏

51CTO技術(shù)棧公眾號