更新软件源
apt update
apt upgrade
安装Podman
apt install podman
配置Podman镜像源
打开podman配置文件 /etc/containers/registries.conf
nano /etc/containers/registries.conf
在底部添加一行
unqualified-search-registries = ["docker.io"]
拉取镜像
podman pull nginx
podman pull php:8.3-fpm
创建Pod
在 Kubernetes (k8s) 以及 Podman 中,Pod 是最小的管理单位,可以包含一个或多个容器。Pod 作为逻辑主机,所有容器共享存储、网络和命名空间。每个 Pod 都有一个唯一的 IP 地址,容器之间可以通过这个 IP 地址进行通信。Pod 的设计使得相关的应用容器能够在同一环境中运行和管理。
podman pod create --name my-web-pod -p 80:80
创建Web目录
mkdir -p web/html
创建Nginx配置文件
nano web/nginx.conf
worker_processes auto;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
server {
listen 80;
server_name localhost;
root /var/www/html;
index index.php index.html index.htm;
location / {
try_files $uri $uri/ =404;
}
location ~ \.php$ {
fastcgi_pass localhost:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
}
在Pod中创建容器
podman run -d --pod my-web-pod --name php-fpm -v ./web/html:/var/www/html:Z php:8.3-fpm
podman run -d --pod my-web-pod --name nginx -v ./web/nginx.conf:/etc/nginx/nginx.conf:Z -v ./web/html:/var/www/html:Z -d nginx
创建测试网页
nano web/html/index.php
<html>
<h1><?php
echo 'Hello World!';
?></h1>
</html>
测试运行状况
浏览器打开 http://服务器IP
,显示 Hello World!
说明成功运行,接下来只需要把你的网页放到web/html中就可以了
—— 评论区 ——