I'm putting this here because it took me a long while to figure this out.
I wanted to improve WordPress's performance by using Redis object caching. My environment is defined in a docker compose.
version: '3.6' services: redis: image: 'redis:alpine' ports: - '6379:6379' restart: always expose: - '6379' wordpress: image: 'wordpress:latest'
There is a handy WordPress plugin for that, but of course, it needs redis to be installed and configured properly. That's the part I struggled with as it could not connect to my redis container.
Normally, Redis should work out-of-the-box with WordPress as long as it is accessible via localhost:6379.
The thing is, in a docker setup the redis instance is accessible via its container name.
So in the above example, in order for WordPress to find it, you need to modify the constant
WP_REDIS_HOST to "redis" in your wp-config.php file.
define('WP_REDIS_HOST', 'redis'); define('WP_REDIS_PORT', '6379');
Additional constants are available. More information is available here.
That's it, really. I hope this helps someone.
Latest comments (2)
Looks like this recipe may longer work. I am running into an issues today with the latest plugin release. FYI:
i did it and works with default theme, but when i try to install hub theme (themeforest.net/item/hub-responsiv...) i got a message like the link has expired.
but if i use a solution like easyengine.io, which also works under docker, i can install the theme without problem, what am i doing wrong?