I'm looking for how to activate a WordPress plugin via a Dockerfile RUN command in the build process.
The relevant command in the Dockerfile is
# activate plugins
RUN wp plugin activate wp-discourse-export --allow-root --path=/var/www/html
The error I'm getting is
Step 10/10 : RUN wp plugin activate wp-discourse-export --allow-root --path=/var/www/html
---> Running in c5dac3f62c4c
Error: This does not seem to be a WordPress install.
Pass --path=`path/to/wordpress` or run `wp core download`.
ERROR: Service 'wordpress' failed to build: The command '/bin/sh -c wp plugin
activate wp-discourse-export --allow-root --path=/var/www/html' returned a non-zero code: 1
If I disable that RUN command, build the image, bring the docker images up, log in to the docker image that was created and run
wp plugin activate wp-discourse-export --allow-root --path=/var/www/html
Plugin 'wp-discourse-export' activated.
Success: Activated 1 of 1 plugins.
the activation succeeds.
How can a WordPress plugin in a docker image be activated in the build process?
Update:
I'm working around the issue by copying a script to the image and then run it later from the host.
in the Dockerfile.
# activate plugins
COPY activate-wordpress-plugins.sh /usr/local/bin/
RUN chmod +x /usr/local/bin/activate-wordpress-plugins.sh
after docker-compose I run this command once.
docker exec -it wordpress_1_7522c9dae310 /usr/local/bin/activate-wordpress-plugins.sh
Update 2
I created a script to bring up the instances and then run the script.
#!/usr/bin/env bash
echo docker-compose up -d
docker-compose up -d
echo docker exec -it $(docker-compose ps -q wordpress) /usr/local/bin/activate-wordpress-plugins.sh
docker exec -it $(docker-compose ps -q wordpress) /usr/local/bin/activate-wordpress-plugins.sh
I think the problem is that WordPress plugin activation requires the WordPress installation to be live, with a valid db connection. You don't have that environment instantiated yet during the image build. Building the image is not the same as running that image in a container.
The appropriate time to activate the plugin would be at launch time, as you suggest,when the container instantiates.