In this post I’ll run over how to setup WP-CLI on a Docker web server image ( so you can easily use it todo a Database find and replace , would is handy when you need to migrate a site from one place to another ).
This presumes you have PHP setup on the command line (which my image did have ). Anyway here goes:
- First in your Docker folder run ‘docker ps’ ( to get the name of the web server image CONTAINER ID )
- Pop that into this command e.g. ‘docker exec -it fdghye5742252 bash’
- You’ll be in a shell on the web server now
- navigate to your web root of the site you want ( my image puts me there already eg /var/www/html )
- download wp-cli and install see https://make.wordpress.org/cli/handbook/guides/installing/
- you can also do this on a volume if you have your webroot setup as a volume linked to your local hard drive
- I didn’t bother with moving it to the bin dir (which would put it on the global path)
- I just did ‘mv wp-cli.phar wp’
- you can then run eg
- ‘./wp –info’
- do your find and replace ‘./wp search-replace ‘https://www.somesite.co.uk’ ‘http://localhost’ –allow-root’
update recently I had a problem with the allow root switch not working, I wrote an alias to allow it. Which is fine as I’m only running docker locally (dont do this on a live site).
alias wp='wp --allow-root'
update update, seems there’s a bug with wp search replace, so went old skool and used https://interconnectit.com/search-and-replace-for-wordpress-databases/ locally ( best not to use this on a live server unless you know the security risks and how to mitigate)
update update update: seems theres an issue with interconnect web script running on docker, so next up is try and use the interconnect command line script.
Disclaimer – Obviously with anything like this be careful and make sure you have a backup, use at your own risk.