如何在docker-compose中的wordpress和wp-cli之间共享卷

时间:2019-01-09 17:13:21

标签: wordpress docker docker-compose wp-cli

在尝试为WordPress主题开发设置可重用的半自动化docker-compose.yml文件时,我在StackOverflow上发现了a very helpful post并实现了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中解决吗?

0 个答案:

没有答案