Using wpcli on wordpress docker-compose installation

1.1k Views Asked by At

Im developing a wordpress theme which running on local with docker-compose. This was my docker-compose file:

version: '2'

services:
  mysql:
    image: mysql:5.7
    restart: always
    ports:
      - 32787:3306
    environment:
      MYSQL_USER: wordpress
      MYSQL_ROOT_PASSWORD: wordpress
      MYSQL_DATABASE: wordpress
      MYSQL_PASSWORD: wordpress

wordpress:
  depends_on:
    - mysql
  image: wordpress
  ports:
    - 32788:80
  restart: always
  volumes:
    - ./:/var/www/html/wp-content/themes/lorraine
  environment:
    WORDPRESS_DB_HOST: mysql:3306
    WORDPRESS_DB_USER: wordpress
    WORDPRESS_DB_PASSWORD: wordpress

The problem with this configuration was that I cant execute wpcli because I cant access to wordpress main folder, so... I changed it by this:

wordpress:
  volumes:
    - ../../:/var/www/html #To generate wordpress structure outside my theme folder
  
wpcli:
  image: wordpress:cli
  volumes_from:
    - wordpress
  links:
    - mysql
  entrypoint: wordpress
  command: "--info"

But I have two problems with this:

  • Created folder are created with this permissions:

drwxr-xr-x 3 www-data www-data 4096 may 14 08:30 plugins

  • docker-compose up -d throw this error:

ERROR: for wpcli Cannot start service wpcli: OCI runtime create failed: container_linux.go:349: starting container process caused "exec: "wordpress": executable file not found in $PATH": unknown ERROR: Encountered errors while bringing up the project.

Do you know how can I fix them?

Update

I fix second problem by changing wp-cli configuration:

wordpress:
  volumes:
    - ../../../:/var/www/html

wpcli:
  image: wordpress:cli
  volumes:
    - ../../../:/var/www/html
  depends_on:
    - mysql
    - wordpress

But folders and files are created with read only permission. I tried adding rw to volumes attribute but it doesnt work.

Do you know how can I fix it?

1

There are 1 best solutions below

1
On

Error says

"executable file not found in $PATH":"Set PATH to point to wordpress executable in your compose file."