在Docker Compose中设置的自定义WordPress主题,在WordPress更新时会被删除
我在一个Docker容器中运行着一个Wordpress实例。我的问题来自于我的自定义主题文件夹——每次WordPress自动更新时,它都会把该文件夹清空。
我的docker-compose.yml配置如下
version: '3.8'
services:
db:
image: mariadb:latest
container_name: seaf_db
restart: unless-stopped
environment:
MYSQL_ROOT_PASSWORD: ${DB_ROOT_PASSWORD}
MYSQL_DATABASE: ${DB_NAME}
MYSQL_USER: ${DB_USER}
MYSQL_PASSWORD: ${DB_PASSWORD}
volumes:
- db_seaf_data:/var/lib/mysql
networks:
- seaf-backend-wrwmqu
wordpress:
depends_on:
- db
build:
context: .
dockerfile: Dockerfile
container_name: seaf_wp
restart: unless-stopped
environment:
WORDPRESS_DB_HOST: db:3306
WORDPRESS_DB_NAME: ${DB_NAME}
WORDPRESS_DB_USER: ${DB_USER}
WORDPRESS_DB_PASSWORD: ${DB_PASSWORD}
CACHE_API_URL: ${CACHE_API_URL}
CACHE_API_URL_GLOBAL: ${CACHE_API_URL_GLOBAL}
CACHE_API_TOKEN: ${CACHE_API_TOKEN}
WORDPRESS_CONFIG_EXTRA: |
define('WP_MEMORY_LIMIT', '512M');
define('WP_ENVIRONMENT_TYPE', 'production');
define('CACHE_API_URL', $_ENV['CACHE_API_URL'] ?? $_SERVER['CACHE_API_URL'] ?? '');
define('CACHE_API_TOKEN', $_ENV['CACHE_API_TOKEN'] ?? $_SERVER['CACHE_API_TOKEN'] ?? '');
volumes:
- ./uploads.ini:/usr/local/etc/php/conf.d/uploads.ini
- ./.htaccess:/var/www/html/.htaccess
# persistant volume for uploads and plugins
- wp_content_seaf_data:/var/www/html/wp-content
# custom theme -- tried to remove it and only keep the COPY from Dockerfile to no avail
- ./custom-theme:/var/www/html/wp-content/themes/custom-theme:ro
ports:
- 80
networks:
- seaf-backend-wrwmqu
volumes:
db_seaf_data:
wp_content_seaf_data:
networks:
seaf-backend-wrwmqu:
external: true
我的Dockerfile :
FROM wordpress:latest
RUN a2enmod rewrite headers
COPY uploads.ini /usr/local/etc/php/conf.d/uploads.ini
COPY ./custom-theme /var/www/html/wp-content/themes/custom-theme
How can I keep my named volume for upload and plugins while not having my custom theme get emptied when WP updates itself automatically ?
解决方案
挂载在 /var/www/html/wp-content 的卷 wp_content_seaf_data 会覆盖镜像拷贝到那里的一切内容,包括自定义主题。WordPress更新后会修改卷中的内容。
Replace:
- wp_content_seaf_data:/var/www/html/wp-content
With:
- wp_uploads:/var/www/html/wp-content/uploads
- wp_plugins:/var/www/html/wp-content/plugins
Keep the theme either:
COPY ./custom-theme /var/www/html/wp-content/themes/custom-theme
or
- ./custom-theme:/var/www/html/wp-content/themes/custom-theme:ro
站内所有文章版权归属LeftHeroAI导航站,无授权禁止任何主体转载、抄袭、复制内容,亦不得私自架设镜像站点。一经侵权,本站将通过法律途径追责。