docker-library / wordpress

Docker Official Image packaging for WordPress
https://wordpress.org/
GNU General Public License v2.0
1.79k stars 1.07k forks source link

--ssh option does not work in wp-cli container #621

Open haynzz opened 3 years ago

haynzz commented 3 years ago

I have tried running wp with the --ssh option on wordpress:cli-2-php7.4 I get an error that basically says that ssh cannot be found. So, I assume ssh is not installed for that image.

tianon commented 3 years ago

Correct -- using SSH inside a container is a bit unique. Can you describe the use case in a bit more detail?

haynzz commented 3 years ago

Thanks for getting back to me so quickly. I am managing my wordpress instances with git and composer. Which means installing plugins etc totally under version control. I want to reduce the amount of things that I do on the admin UI, so that I can assure the different environments (local, staging, production) are the same. When I install a plugin via composer I want to activate it via WP–Cli. I thought it may come in handy if I could run wp-cli from the CI-container and I planned using this wp-cli image for that. I was thinking I would not need to maintain wp-cli installations/version on the hosting server this way. Fast forward, I now realised that I can't consistently follow-through with this approach, since composer does not offer ssh. Still, I thought it's worth mentioning that a documented wp-cli feature is blocked by the way the container image is built. I think it should at least be mentioned in the documentation of the image somewhere.

tianon commented 3 years ago

I appreciate the added detail.

The reason I'm still hesitant is because using even just the SSH client inside a container is pretty complex, especially since you'll ideally be using key-based authentication, so you need to get the (private!) keys from your host into the container in precisely the right place for them to get picked up, so it's fiddly enough that it seems pretty reasonable to expect users who need that to install openssh-client themselves, especially since it'll install so quickly (apk add --no-cache openssh-client).

haynzz commented 3 years ago

Yeah, good point. That's also what I've done in the end. I created my own Docker image from this one. It took me a while though to figure out that I had to add USER root before the above install command. In my exact case I could have used password instead of key-based authentication, but with CI it's correct what you say. I'd still like to add that it didn't seem more complex for me to get SSH running in a container than it is on my host machine. So, if you want ssh you will have to know what you're doing no matter if it's a docker container or on my host machine. I normally try to use existing docker images instead of creating my own Dockerfiles and building them. Specifically because then I have to push them to a registry or something so they work with CI. So, that version was much more fiddly for me. And as I have mentioned there was no easy way for me to install openssh-client while in a running wp-cli container because of permission problems. sudo did not work and I could also not switch to root.
As I said, It's probably just worth mentioning that you'll need to fork-off your own Image to be able to use the --ssh option in the README or where-ever.