3

In trying to setup a reusable, semi-automated docker-compose.yml file for WordPress theme development, I found a very helpful post on StackOverflow and implemented the docker-compose.yml that vstm provided.

The example works very well, and I had been using it to add wp-cli commands for adding plugins, changing options, and deleting pre-loaded themes and plugins.

But now, I'm getting nothing but permission errors and I have tried manually changing wp-cli to user: '33:33' as well as the original user:xfs

I started over from the example and the first problem I run into is adding an additional volume shared between the two for the theme I'm developing. My theme name is default so that volume name is correct.

Here's what I have so far:

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:

Here's the output log from the wp-cli console in kitematic:

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.

Everything was working perfectly on at least 5 sites and then I assume there was a change in docker recently and I updated and broke all of them. Any ideas how this can be remedied in the latest Docker?

Mike Wish
  • 41
  • 7
  • maybe issue related to `./default/:/var/www/html/wp-content/themes/default` string. can you replace linew with it to `./default/:/var/www/html/wp-content` and try? – vvchik Jan 09 '19 at 19:46
  • @vvchik I think that will put the "default" theme in the wrong place inside the container, but I did try it and did not have any luck. I'm still getting all sorts of permissions errors. Its strange because my co-worker uses the same docker-compose file and it works perfectly. What could cause that!? – Mike Wish Jan 09 '19 at 22:04
  • I've tried to run your compose and it works with my modifications. Do you need access to default folder from host machine? If no, try to make it shared volume similar to wp_data. If yes, try to remove/rename data folder in your current folder. – vvchik Jan 10 '19 at 01:18
  • @vvchik, I do need access to default folder, because I'm doing theme development. If i don't mount a volume for it, the container can not see my theme. In your instance, did you try to install a plugin or update wordpress? Thats where I get the new errors. Thanks so much for your efforts. – Mike Wish Jan 10 '19 at 13:19
  • @vvchik I think I may have resolved it. It seems like it was a change introduced in a new version of WP-CLI. I reverted to `wordpress:cli-1` and now all my commands and my install is working perfectly. I wonder what changes to the user occurred in the new WP CLI... – Mike Wish Jan 10 '19 at 13:48
  • UID 33 is for debian, if you're using alpine its 82 – RayZor Aug 23 '21 at 16:18

0 Answers0