创建 pod

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
sudo vim /etc/containers/registries.conf
[[registry]]
prefix = "docker.io"
location = "docker.m.daocloud.io" # 使用国内镜像加速

podman build -t php74-dev:latest -f Containerfile .
podman pull m.daocloud.io/docker.io/library/nginx:stable-alpine

sudo sysctl -w net.ipv4.ip_unprivileged_port_start=80
echo "net.ipv4.ip_unprivileged_port_start=80" | sudo tee /etc/sysctl.d/99-podman-ports.conf
sudo sysctl -p /etc/sysctl.d/99-podman-ports.conf

podman pod stop work-pod 2>/dev/null || true
podman pod rm -f work-pod 2>/dev/null || true

podman pod create --name work-pod -p 80:80

podman run -d --pod work-pod \
--name nginx \
-v /home/k-k/Documents/www:/var/www:Z \
-v /home/k-k/Documents/pod-conf/conf.d:/etc/nginx/conf.d:ro,Z \
nginx:stable-alpine

podman run -d --pod work-pod \
--name php74-dev \
-v /home/k-k/Documents/www:/var/www:Z \
localhost/php74-dev:latest php-fpm -F

composer install --ignore-platform-req=ext-grpc

chown -R www-data:www-data /var/www/work/erp_api/storage/logs /var/www/work/erp_api/bootstrap/cache
OR
chmod 777 -R erp_api/storage/ erp_api/bootstrap/ erp_api/public

# 查看隐藏容器
podman ps -a --external
podman unmount <CONTAINER ID>
podman rm <CONTAINER ID> <CONTAINER ID>
podman rmi <CONTAINER ID> <CONTAINER ID>

Containerfile

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# 使用 PHP 7.4 官方镜像
FROM php:7.4-fpm

# 配置清华大学镜像源
RUN echo "deb https://mirrors.tuna.tsinghua.edu.cn/debian/ bullseye main non-free contrib" > /etc/apt/sources.list && \
echo "deb-src https://mirrors.tuna.tsinghua.edu.cn/debian/ bullseye main non-free contrib" >> /etc/apt/sources.list && \
echo "deb https://mirrors.tuna.tsinghua.edu.cn/debian/ bullseye-updates main" >> /etc/apt/sources.list && \
echo "deb-src https://mirrors.tuna.tsinghua.edu.cn/debian/ bullseye-updates main" >> /etc/apt/sources.list \

# 配置国内 PECL 镜像
RUN echo "pecl.php.net = https://mirrors.aliyun.com/pecl" >> /usr/local/etc/php/conf.d/pecl.ini

# 安装依赖项
RUN apt-get update && apt-get install -y \
libpng-dev \
libjpeg62-turbo-dev \
libfreetype6-dev \
libzip-dev \
libmagickwand-dev \
libicu-dev \
libxml2-dev \
libssl-dev \
libbz2-dev \
git \
zlib1g-dev \
libonig-dev \
libc-client-dev \
libkrb5-dev \
&& rm -rf /var/lib/apt/lists/*

# 安装 PHP 扩展
RUN docker-php-ext-configure imap --with-kerberos --with-imap-ssl \
&& docker-php-ext-install imap

RUN docker-php-ext-configure gd --with-freetype --with-jpeg \
&& docker-php-ext-install \
bcmath \
gd \
pdo_mysql \
mysqli \
zip \
exif \
fileinfo \
mbstring \
intl \
soap \
sockets \
&& pecl install xlswriter imagick redis-5.3.7 \
&& docker-php-ext-enable xlswriter imagick redis

# 安装 Composer
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer

RUN echo "upload_max_filesize = 50M" >> /usr/local/etc/php/conf.d/custom.ini && \
echo "post_max_size = 50M" >> /usr/local/etc/php/conf.d/custom.ini && \
echo "memory_limit = 512M" >> /usr/local/etc/php/conf.d/custom.ini && \
echo "display_errors = On" >> /usr/local/etc/php/conf.d/custom.ini && \
echo "error_reporting = E_ALL" >> /usr/local/etc/php/conf.d/custom.ini && \
echo "date.timezone = Asia/Shanghai" >> /usr/local/etc/php/conf.d/custom.ini && \
# 优化 opcache(加速 PHP 执行)
echo "opcache.enable = 1" >> /usr/local/etc/php/conf.d/custom.ini && \
echo "opcache.validate_timestamps = 1" >> /usr/local/etc/php/conf.d/custom.ini && \
echo "opcache.revalidate_freq = 0" >> /usr/local/etc/php/conf.d/custom.ini # 开发环境实时刷新代码

# 设置工作目录
WORKDIR /var/www

# 暴露端口
EXPOSE 9000

# 启动命令
CMD ["php-fpm", "-F"]

nginx config

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
server {
listen 80;
server_name test-erp.com;

# 现在 root 和容器内路径完全一致
root /var/www/erp_api/public;
index index.php index.html index.htm;

location / {
try_files $uri $uri/ /index.php?$query_string;
}

location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}

# 安全设置
location ~ /\. {
deny all;
}
}