-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Include WP-CLI in all WordPress images #283
Comments
Having the same problem. It would be nice to be included in WP image. |
While it is a great tool, it is not included in the image for a number of reasons:
|
1. https://codex.wordpress.org/Installing_WordPress DOES contain the suggestion to use wp-cli:
Installing through wp-cli
wp-cli is a great command line tool with which you can easily install and update WordPress and themes and extensions.
2. Most users need it (those kind of users who mess with Docker, most of them), and it’s tiny so it doesn’t really matter.
3. WP-CLI can be used from WordPress image or anyone can craft a their own WP-CLI-only image if they desire so.
The fact that WP-CLI and WP images are based on different distribution is troublesome as linked issues show.
Including WP-CLI will make wp so much more programmatically manageable.
|
Personally, I use it for managing users, roles, and plugin activation/dectivation from CLI. I agree that:
|
Yes, I also found it very useful! And I think that is lightweight and really is not intrusive for people that not use it. |
Any updates on this? Are there any plans to include wp-cli in WordPress docker images? |
I too am interested to see. Currently using a variant just to get CLI running. Feels like this should be baked in. |
I also agree. I feel like anyone who's using Docker to manage WordPress installations is very, very likely to use CLI too. |
I also anticipated this being built in. Considering the barrier to entry is understanding and using Docker, WP CLI would be a justifiable inclusion for devops workflows. |
Are there news on this? It would really be a good choice to do it! |
An issue with relying on the current A possible solution to this would be to use one of the Alpine WordPress images, but apparently using one of these would require you also spin up a separate Apache container, which I expect most people aren't interested in doing. |
There shouldn't be anything stopping the CLI image from running as an arbitrary user, ala |
@tianon Yeah, turned out to be a different issue. Thanks. |
I have created some images which include |
What is the point of running FROM wordpress:cli-php7.4
USER root
COPY wait-for-it.sh /usr/local/bin/wait-for-it
RUN chown www-data:www-data /usr/local/bin/wait-for-it && \
chmod +x /usr/local/bin/wait-for-it
COPY entrypoint.sh /usr/local/bin/entrypoint.sh
RUN chown www-data:www-data /usr/local/bin/entrypoint.sh && \
chmod +x /usr/local/bin/entrypoint.sh
RUN mkdir /backups && chown www-data:www-data /backups
USER www-data
WORKDIR /backups
RUN mkdir ~/.wp-cli && echo "path: /var/www/html" > ~/.wp-cli/config.yml
ENTRYPOINT ["entrypoint.sh"]
|
Sure you can start a new container with wp-cli, plug it to your wordpress For reference, a lot of apps have their CLI either part of the project itself (NextCloud, Symfony based apps, etc...) or are added to their containers for convenience. If some are interested, I also developed for my company a docker container based on the WP official images and which adds wp-cli with several other libraries like memcached and LDAP support : https://github.com/Monogramm/docker-wordpress |
So why bundle
|
When I say "manage your containers manually", I mean to manually create new containers with wp-cli to manage a Wordpress instance. Having wp-cli in the container can allow you to manage your instance without creating a new container.
I agree with you on those, though regarding the last point, it's usually easier to have each WP instance use their own wp-cli, and I think maybe better if you want to run wp-cli operations on several WP instances at the same time. Anyway, I do not mind WP's decision to keep their container minimal. |
What about bundling that minimal |
It would make sense for a cronjob purpose , but otherwise it would be more problematic since you would need to stop the container first before switching to another WP instance... |
I don't get the point, can you explain with use case? |
It's as you mentioned before: the cli image can be used to manage a wp installation in another container. To do that with the container, you need to mount the
So if you have 2 wordpress containers, A & B, respectively with the following volumes:
If you have a single wp-cli container, with a volume mounted to WP A ( In that case, it's probably easier to just have a wp-cli container for each of your WP instances... |
But if you have |
No you don't. That's the big advantage. If you're using docker-compose, you can just run the following command:
And just replace the |
So you have a lot of wordpress sites in one |
Well, that's not my use case, I usually only have one WordPress at the time, but this is the use case for the point you mentioned.
Why this would be relevant ? |
@madmath03 NAME=wpdev && docker run -it \
--volumes-from="${NAME}_wordpress_1" \
--network="${NAME}_default" \
wordpress:cli-php7.4 \
\
/bin/bash -c "wp core update"
Success: WordPress is up to date. Or if you have non-consistent naming place ---------- 420 buk 345233 236 Jan 26 14:06 .env
---------- 420 buk 345233 124 Jan 26 14:06 docker-compose.yaml # .env
NETWORK_NAME=mynetwork
WORDPRESS_CONTAINER=mycontainer # docker-compose.yaml
networks:
test:
name: $NETWORK_NAME
services:
wordpress:
container_name: $WORDPRESS_CONTAINER
networks:
- test
mysql:
networks:
- test And then run: source .env && \
docker run -it \
--volumes-from="${WORDPRESS_CONTAINER}" \
--network="${NETWORK_NAME}" \
wordpress:cli-php7.4 \
\
/bin/bash -c "wp core update"
Success: WordPress is up to date. To use
Or use labels :) |
This is not a viable solution and the community has told you this in multiple different ways. The wp-cli is the only SANE way to manage wordpress in a Docker environment, period.
Your use case is irrelevant.
Also not effective. Not everyone has docker-compose installed, or even uses Docker with OCI containers to begin with. This is a hack, and not a good one at that. People are repeatedly telling you that the "other container solution" is not effective, doesn't fit the general use case of wordpress in a standalone container, and that wp-cli is not optional or arbitrary. Furthermore the excuses for why it's not included are absolutely nonsensical - if you're that concerned about the size of the container, make a "minimal" tag that doesn't include it, which is actually the idiom that many containers use in the first place. |
Yet another reason why your second container hack isn't viable, straight from the documentation itself:
|
Please keep the discussion respectful. |
This comment was marked as off-topic.
This comment was marked as off-topic.
could not we just post here a dockerfile, which is FROM wordpress and adds a CLI installation to the image, then using that? |
There is also problem we did not mentioned here before when running cli from other container. In the old days for the cli it was enough to know the path for the wp installation folder, so multiple wp installations could be handled by simply using the default path or the --path switch of the cli. So we may think that using docker volumes creatively and allowing the necessary network connectivity we can still use one cli container for multiple wp docker containers. However there is a trap, which makes this thing more painfully what it seems: The newer wp docker images do not write the db info and credentials to wp-config.php, instead just write environment variable references to the wp-config.php. This means, that cli can not get that information by simply reading the pointed wp folders wp-config.php. If the cli is running in other container, it is impossible for it to get the values those env variables. The only way is, to set the same env variables redundantly in the cli container too. So we must manage multiple sets of environment variables and spin up the cli image every time with different set of the environment variables, because pointing to a wp installation folder is not enough anymore |
This comment was marked as spam.
This comment was marked as spam.
This is also now a big issue with Docker-based management systems like Coolify. I finally figured out a way to get the WP-CLI container to talk to my WP container, but then I'll need to do all those steps for my other sites. But even then, I have to enter or exec the WP-CLI container specific to that site in order to do things with the other container. It would be so much easier, faster, and simpler to package them together (or simply offer a third image like This issue is almost 7 years old. 😢 |
For a while now,
WP-CLI
has become the official way to manage WordPress from scripts / command line.But if you glance through
docker-entrypoint.sh
, the current way of installing WordPress and hackingwp-config.php
withsed
andawk
is not pretty and error-prone compared to a bunch ofWP-CLI
commands likeWP-CLI
doesn't take too much space, and it's become essential. I propose to:WP-CLI
in all official WordPress images,WP-CLI
image,docker-entrypoint.sh
usingWP-CLI
.It will show the community the relevant way of managing WordPress from the command line, and will make it easier to actually use the image later on. It will also solve #256.
The text was updated successfully, but these errors were encountered: