Add support for `docker-compose run` to the `ssh` option by johnbillion · Pull Request #5637 · wp-cli/wp-cli
The docker: and docker-compose: schemes for the ssh option are useful, but they only work when the target container is already running and therefore supports running a shell command via docker[-compose] exec.
Some environments, for example the wordpress-develop local development environment, run WP-CLI via a container that only starts when needed and therefore requires the use of run instead of exec. The ssh option in WP-CLI doesn't currently support running commands in a container in this manner.
The change in this PR introduces support for a docker-compose-run scheme for the ssh option which runs the command via docker compose run <container> <cmd>.
With this support in place you could put the following config into the root of any project that uses wordpressdevelop/cli and then simply use wp <cmd> instead of npm run env:cli -- <cmd> or docker-compose run cli -- <cmd>.
# wp-cli.yml ssh: docker-compose-run:cli
You'll note that the command needs to be constructed differently to all the other schemes supported by the ssh option, crucially that the command cannot be wrapped in escapeshellarg() because docker-compose run <container> <cmd> doesn't support the command being quoted. I am honestly not sure of the security implications of this, we might need to consult someone a bit more familiar with the internals of sending commands via run.
Feedback welcome.