当前位置:网站首页 > 更多 > 玩电脑 > 正文

[玩转系统] 在 Windows Server 上使用 Podman Desktop

作者:精品下载站 日期:2024-12-14 05:42:32 浏览:12 分类:玩电脑

在 Windows Server 上使用 Podman Desktop


在 Windows Server 上使用容器是划分应用程序部署的好方法,甚至可以在 Windows Server 内的其他操作系统(如 Linux)上运行应用程序。

适用于 Windows Server 的最佳容器应用程序之一是 Podman Desktop。 Podman Desktop 由 RedHat 创建和开发,支持 Podman、Docker 和许多其他容器技术。以下是如何在 Windows Server 上使用它。

[玩转系统] 在 Windows Server 上使用 Podman Desktop

在 Windows 服务器上安装 Chocolatey

Chocolatey Windows 包管理器使在 Windows Server 上安装大量应用程序变得更加容易,因为它允许用户运行 PowerShell 命令来获取流行的应用程序,而不是处理下载 EXE 安装程序文件。

Chocolatey 工具将使 Podman 桌面应用程序在 Windows Server 上运行变得更加容易。首先,在 Windows Server 桌面上打开一个 PowerShell 窗口。

PowerShell 窗口打开并可供使用后,运行以下命令以在您的系统上设置 Chocolately 包管理器。

Set-ExecutionPolicy Bypass -Scope Process -Force; [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; iex ((New-Object System.Net.WebClient).DownloadString('https://community.chocolatey.org/install.ps1'))

在 PowerShell 窗口中输入上述命令后,屏幕上会出现一些提示。按照这些提示在您的系统上安装 Chocolatey 包管理器。

当系统上安装了 Chocolatey 包管理器后,您可以通过运行 choco 命令来测试它是否正常工作。如果输入后没有任何反应,则需要重新启动 PowerShell 窗口。

在 Windows Server 上安装 Podman 桌面应用程序

既然安装了 Chocolatey 包管理器,Podman 桌面应用程序就很容易在 Windows Server 上安装。使用 choco install 命令设置 Podman Desktop。

choco install podman-desktop

Chocolatey 包管理器在安装 Podman Desktop 时会提示一些问题。按照这些提示操作,让一切在您的系统上正常运行。

Chocolatey 应用程序安装完 Podman Desktop 后,您可以关闭 PowerShell 窗口。 Podman Desktop 现在应该可以在“开始”菜单中使用。

在 Windows Server 上启用虚拟机功能

如果不启用虚拟化,Podman Desktop 无法在 Windows Server 上执行容器。要启用此功能,请打开 PowerShell 窗口并输入以下命令。

dism.exe /online /enable-feature /featurename:VirtualMachinePlatform /all /norestart

执行上述命令后,您将能够在 Windows Server 上充分利用 Podman Desktop。

如何在 Windows Server 上的 Podman Desktop 中创建容器

使用 Chocolatey 包管理器在 Windows Server 上成功安装 Podman Desktop 后,打开该应用程序。您可以通过在 Windows Server“开始”菜单中搜索来找到 Podman Desktop。

打开 Podman 桌面应用程序后,您必须设置映像“注册表”。 “Registry”提供容器镜像,您可以快速下载并使用镜像创建容器。首先,单击左侧边栏中的齿轮图标以访问选项区域。

在 Podman Desktop 界面中,找到“注册表”,然后使用鼠标选择它。默认情况下,设置了四个注册表:“Docker Hub”、“Red Hat Quay”、“GitHub”和“Google 容器注册表”。如果您需要登录这些注册表中的任何一个,请单击相应注册表旁边的“配置”,然后登录您的帐户。

注意:如果您需要向 Podman Desktop 添加其他容器注册表,请单击“添加注册表”按钮,然后添加您的容器注册表。

在 Podman Desktop 中设置注册表后,在单独的窗口中打开记事本。您现在必须编写一个“Containerfile”。 “Containerfile”是一个指令集,告诉 Podman Desktop 要做什么。这是容器文件的样子。

 # Step 1: Specify Base Image (example: ubuntu:latest)
FROM base-image:tag

# Step 2: Set Metadata (Optional)
LABEL maintainer="[email protected]"

# Step 3: Run Commands
RUN command-to-install-something

# Step 4: Copy Files
COPY ./local-file-path /container-file-path

# Step 5: Set Environment Variables
ENV VARIABLE_NAME value

# Step 6: Expose Ports
EXPOSE port-number

# Step 7: Set Working Directory
WORKDIR /container-directory

# Step 8: Define Command or Entry Point
CMD ["command-to-run", "argument1", "argument2"

例如,如果您希望使用最新的 Ubuntu 映像部署基本的 Apache Web 服务器,它将如下所示:

# Use the official Ubuntu base image
FROM ubuntu:latest

# Update the package list and install the Apache server
RUN apt-get update && \
    apt-get install -y apache2

# Copy over any necessary files or directories (optional)
# COPY ./public-html/ /var/www/html/

# Expose the port Apache will listen on
EXPOSE 80

# Start the Apache server
CMD ["apachectl", "-D", "FOREGROUND"]

将记事本中的文本保存为“Containerfile”。然后,返回 Podman Desktop,然后单击“创建容器”按钮。选择此按钮后,选择“Containerfile 或 Dockerfile”。

[玩转系统] 在 Windows Server 上使用 Podman Desktop

选择“Containerfile 或 Dockerfile”后,选择“Containerfile 路径”,然后浏览找到您之前在记事本中创建的“Containerfile”。然后,选择构建的图像的保存位置以及图像的名称。最后,单击“Build”按钮在 Podman Desktop 中构建容器映像。

[玩转系统] 在 Windows Server 上使用 Podman Desktop

构建过程将需要一秒钟才能完成。该过程完成后,找到“完成”按钮,然后用鼠标选择它。选择“完成”按钮后,Podman Desktop 将引导您完成在生产中部署容器的过程。

[玩转系统] 在 Windows Server 上使用 Podman Desktop

您需要 登录账户 后才能发表评论

取消回复欢迎 发表评论:

关灯