在尝试为 WordPress 主题开发设置可重用、半自动化的 docker-compose.yml 文件时,我在 StackOverflow 上找到了一篇非常有用的帖子,并实现了 vstm 提供的 docker-compose.yml。
该示例运行良好,我一直在使用它来添加 wp-cli 命令,以添加插件、更改选项以及删除预加载的主题和插件。
但是现在,除了权限错误,我什么也没有得到,我尝试手动将 wp-cli 更改user: '33:33'
为原始版本user:xfs
我从示例重新开始,遇到的第一个问题是为我正在开发的主题添加一个在两者之间共享的附加卷。我的主题名称是default
这样的卷名是正确的。
这是我到目前为止所拥有的:
version: "2.3"
services:
db:
image: mysql:5.7
volumes:
- db_data:/var/lib/mysql
restart: always
environment:
MYSQL_ROOT_PASSWORD: somewordpress
MYSQL_DATABASE: wordpress
MYSQL_USER: wordpress
MYSQL_PASSWORD: wordpress
wordpress:
depends_on:
- db
image: wordpress:latest
ports:
- 8000:80
restart: always
environment:
WORDPRESS_DB_HOST: db:3306
WORDPRESS_DB_NAME: wordpress
WORDPRESS_DB_USER: wordpress
WORDPRESS_DB_PASSWORD: wordpress
WORDPRESS_TABLE_PREFIX: "wp_"
WORDPRESS_DEBUG: 1
# vstm: add shared volume
volumes:
- wp_data:/var/www/html
- ./default/:/var/www/html/wp-content/themes/default
wordpress-cli:
depends_on:
- db
- wordpress
image: wordpress:cli
# vstm: This is required to run wordpress-cli with the same
# user-id as wordpress. This way there are no permission problems
# when running the cli
user: xfs
# vstm: The sleep 10 is required so that the command is run after
# mysql is initialized. Depending on your machine this might take
# longer or it can go faster.
command: >
/bin/bash -c '
sleep 10;
wp core install --path="/var/www/html" --url="http://localhost:8000" --title="Local Wordpress By Docker" --admin_user=admin --admin_password=secret --admin_email=foo@bar.com;
wp plugin install classic-editor;
'
# vstm: add shared volume
volumes:
- wp_data:/var/www/html
- ./default/:/var/www/html/wp-content/themes/default
volumes:
db_data:
# vstm: add shared volume
wp_data:
这是 kitematic 中 wp-cli 控制台的输出日志:
Warning: Unable to create directory wp-content/uploads/2019/01. Is its parent directory writable by the server?
Success: WordPress installed successfully.
Installing Classic Editor (1.3)
Warning: Failed to create directory '/etc/X11/fs/.wp-cli/cache/': mkdir(): Permission denied.
Downloading installation package from https://downloads.wordpress.org/plugin/classic-editor.1.3.zip...
Unpacking the package...
Warning: Could not create directory.
Error: No plugins installed.
一切都在至少 5 个站点上运行良好,然后我认为最近 docker 发生了变化,我更新并破坏了所有站点。有什么想法可以在最新的 Docker 中解决这个问题吗?