使用docker compose部署files.gallery
本地的目录结构
gallery/
│
├── docker-compose.yml
│
├── www/ ← 网站根目录(index.php / Files Gallery)
│ └── gallery/index.php
│
├── php/
│ └── custom.ini ← PHP 自定义配置
│
└── apache/
└── vhost.conf ← Apache 虚拟主机配置(禁止目录访问)
创建本地目录
mkdir gallery
cd gallery
mkdir www php apache
创建vhost.conf
cd apache
sudo nano vhost.conf
<VirtualHost *:80>
ServerName localhost
DocumentRoot /var/www/html
DirectoryIndex index.php index.html
<Directory /var/www/html>
Options -Indexes +FollowSymLinks
AllowOverride All
Require all granted
</Directory>
ErrorLog /var/log/apache2/error.log
CustomLog /var/log/apache2/access.log combined
</VirtualHost>
此处因为本地目录设置调整为
<VirtualHost *:80>
ServerName localhost
DocumentRoot /var/www/html/gallery
DirectoryIndex index.php index.html
<Directory /var/www/html/gallery>
Options -Indexes +FollowSymLinks
AllowOverride All
Require all granted
</Directory>
ErrorLog /var/log/apache2/error.log
CustomLog /var/log/apache2/access.log combined
</VirtualHost>
ctrl+x,y保存。
创建custom.ini
cd ..
cd php
sudo nano custom.ini
upload_max_filesize = 200M
post_max_size = 200M
memory_limit = 512M
max_execution_time = 300
下载官方的index.php放到./www/gallery下
创建docker-compose.yml文件
version: "3.9"
services:
php_apache:
image: php:8.2-apache
container_name: php_apache
restart: unless-stopped
ports:
- "8080:80"
volumes:
- ./www:/var/www/html
- ./php/custom.ini:/usr/local/etc/php/conf.d/custom.ini:ro
- ./apache/vhost.conf:/etc/apache2/sites-enabled/000-default.conf:ro
# ✅ 关键:启动时自动安装 GD 扩展(无需 Dockerfile)
command: >
bash -c "
apt-get update &&
apt-get install -y libfreetype6-dev libjpeg62-turbo-dev libpng-dev libwebp-dev libavif-dev &&
docker-php-ext-configure gd --with-freetype --with-jpeg --with-webp --with-avif &&
docker-php-ext-install gd &&
apache2-foreground
"
sudo docker compose up -d
这个时候访问ip:8080端口即可访问程序。
部署完成了。
另外一种部署(先构建在部署)
目录结构为
gallery/
├── Dockerfile
├── docker-compose.yml
├── www/gallery/
├── php/
│ └── custom.ini
└── apache/
└── vhost.conf
在上面的基础上增加Dockerfile
sudo nano Dockerfile
FROM php:8.2-apache
ENV DEBIAN_FRONTEND=noninteractive
RUN apt-get update && \
apt-get install -y --no-install-recommends \
libfreetype6-dev libjpeg62-turbo-dev libpng-dev libwebp-dev libavif-dev \
libzip-dev libonig-dev libxml2-dev ffmpeg ca-certificates && \
docker-php-ext-configure gd --with-freetype --with-jpeg --with-webp --with-avif && \
docker-php-ext-install -j$(nproc) gd exif zip mbstring fileinfo && \
a2enmod rewrite && \
apt-get clean && rm -rf /var/lib/apt/lists/*
WORKDIR /var/www/html
创建docker-compose.yml
sudo nano docker-compose.yml
version: "3.9"
services:
php_apache:
build: .
container_name: php_apache
restart: unless-stopped
ports:
- "8080:80"
volumes:
- ./www:/var/www/html
- ./php/custom.ini:/usr/local/etc/php/conf.d/custom.ini:ro
- ./apache/vhost.conf:/etc/apache2/sites-enabled/000-default.conf:ro
运行
sudo docker compose build
sudo docker compose up -d
部署完成。