一个「开箱即用」的极简 Nginx 容器镜像,专为 WordPress 及静态站点优化。
基于官方 Alpine Linux,多平台构建,体积 < 5 MB,启动秒级完成。
linux/amd64、linux/arm64 等主流架构0.0.0.0nobody 用户运行,避免以 root 执行 Nginx/etc/nginx/nginx.conf 或 /usr/share/nginx/htmldocker run -d --name web \
-p 80:80 \
-v $PWD/html:/usr/share/nginx/html:ro \
micrograils/wp-nginx:latest
浏览器访问 http://localhost 即可看到挂载目录下的 index.html。
docker run -d --name web \
-p 80:80 \
-v $PWD/nginx.conf:/etc/nginx/nginx.conf:ro \
-v $PWD/site:/usr/share/nginx/html:ro \
micrograils/wp-nginx:latest
services:
nginx:
image: micrograils/wp-nginx:latest
container_name: wp-nginx
ports:
- "80:80"
volumes:
- ./default.conf:/etc/nginx/http.d/default.conf
- ${LOCAL_WORDPRESS}:/var/www/html
depends_on:
- php
restart: always
networks:
- wp-network
healthcheck:
test: ["CMD", "nc", "-z", "localhost", "80"]
interval: 5s
timeout: 3s
retries: 5
php:
image: micrograils/wp-php82:latest
container_name: wp-php
environment:
WORDPRESS_DB_HOST: mariadb
WORDPRESS_DB_NAME: ${WORDPRESS_DB_NAME}
WORDPRESS_DB_USER: ${WORDPRESS_DB_USER}
WORDPRESS_DB_PASSWORD: ${WORDPRESS_DB_PASSWORD}
volumes:
- ${LOCAL_WORDPRESS}:/var/www/html
depends_on:
- mariadb
restart: always
networks:
- wp-network
healthcheck:
test: ["CMD", "nc", "-z", "localhost", "9000"]
interval: 5s
timeout: 3s
retries: 5
mariadb:
image: micrograils/wp-mariadb:latest
container_name: wp-mariadb
environment:
MARIADB_ROOT_PASSWORD: ${MARIADB_ROOT_PASSWORD}
MARIADB_DATABASE: ${WORDPRESS_DB_NAME}
MARIADB_USER: ${WORDPRESS_DB_USER}
MARIADB_PASSWORD: ${WORDPRESS_DB_PASSWORD}
volumes:
- ${LOCAL_MARIADB_DATA}:/var/lib/mysql
restart: always
networks:
- wp-network
healthcheck:
test: ["CMD", "nc", "-z", "localhost", "3306"]
interval: 5s
timeout: 3s
retries: 5
wordpress:
image: micrograils/wp-wordpress:6.8.3
container_name: wp-wordpress
environment:
WORDPRESS_DB_HOST: mariadb
volumes:
- ${LOCAL_WORDPRESS}:/var/www/html
networks:
wp-network:
driver: bridge
其中,micrograils/wp-php82 镜像基于官方 PHP 8.2 镜像,并安装了 php-fpm 和 php-mysql 扩展。对应的有 micrograils/wp-php83 和 micrograils/wp-php84 等镜像供按需调整;
micrograils/wp-wordpress:6.8.3 镜像基于官方 WordPress 6.8.3 镜像,可按需更改版本号。
.env 示例:
# db info.
MARIADB_ROOT_PASSWORD=wordpress
WORDPRESS_DB_NAME=wordpress
WORDPRESS_DB_USER=wordpress
WORDPRESS_DB_PASSWORD=wordpress
# local volume.
LOCAL_WORDPRESS=./wordpress
LOCAL_MARIADB_DATA=./mariadb_data
Nginx 配置示例片段:
server {
listen 80;
server_name _;
root /var/www/html;
index index.html index.php;
access_log /var/log/nginx/host1-access.log;
error_log /var/log/nginx/host1-error.log;
location / {
try_files $uri $uri/ /index.php?$args;
}
location ~ \.php$ {
fastcgi_pass wp-php:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
# 如果前面有 https 的反向代理
fastcgi_param HTTPS on;
fastcgi_param HTTP_X_FORWARDED_PROTO https;
}
location ~ /\.ht {
deny all;
}
}
启动:
docker-compose up -d
浏览器访问 http://localhost 即可看到 WordPress 安装页面。
| 项目 | 说明 |
|---|---|
| 暴露端口 | 80/TCP |
| 默认工作目录 | /usr/share/nginx/html |
| 主配置文件 | /etc/nginx/nginx.conf |
| 默认主机配置 | /etc/nginx/http.d/default.conf |
Q:容器内找不到站点?
A:请把网页文件挂载到 /usr/share/nginx/html,或替换 /etc/nginx/nginx.conf 以改变根目录。
Q:如何开启目录浏览?
A:在自定义 nginx.conf 对应 location 加 autoindex on; 即可。
Q:想使用 Alpine 其他版本?
A:构建时指定 ALPINE_VERSION 参数:
docker build --build-arg ALPINE_VERSION=3.21.0 \
-t micrograils/wp-nginx:3.21.0 .
默认使用 Alpine 3.23。
GitHub 仓库
欢迎提 Issue / PR,一起让 Web 服务更轻更快!
micrograils/wp-nginx
轻到飞起,快若闪电。
Content type
Image
Digest
sha256:12dff969f…
Size
4.5 MB
Last updated
3 months ago
docker pull micrograils/wp-nginx