How to 'wp package install' in wpcli docker container
Using docker-compose with a config such as
# ...
wpcli:
depends_on:
- wordpress
image: wordpress:cli
user: 1000:1000
command: tail -f /dev/null
volumes:
- ./wordpress:/var/www/html
environment:
- WORDPRESS_DB_HOST=mariadb:3306
- WORDPRESS_DB_USER=wordpress
- WORDPRESS_DB_NAME=wordpress
- WORDPRESS_DB_PASSWORD=${MARIADB_PASSWORD}
You need to install the package in the container as root to avoid
Error: Composer directory '/.wp-cli/packages' for packages couldn't be created: mkdir(): Permission denied
Use the following command to install a package
docker-compose exec -u root wpcli wp package install wp-cli/profile-command:@stable --allow-root