Support » Plugin: Redis Object Cache » Docker: redis in different container, redis-cli connects, redis object cahce not

  • Resolved Gymnae

    (@gymnae)


    I’ve spun up a docker image for wordpress connecting to my installed redis container running on the same host. A nextcoud installation is already using this redis container succesfully. Both the wordpress and owncloud container link to the redis container via docker linkage and are available via ENV variables.

    Trying redis-cli -h redis inside the wordpress container works – PING returns PONG
    There is no password set on the redis server.

    Here are the diagnostics:

    PHP Version: 7.1.5
    Multisite: No
    Redis: 3.1.2
    Predis: 1.1.1
    Status: Not Connected
    Client: PECL Extension (v3.1.2)
    WP_REDIS_CLIENT: "pecl"
    WP_REDIS_HOST: "redis"
    WP_CACHE_KEY_SALT: ""
    Drop-in: Valid
    Global Prefix: "wp_"
    Blog Prefix: "wp_"
    Global Groups: ["blog-details","blog-id-cache","blog-lookup","global-posts","networks","rss","sites","site-details","site-lookup","site-options","site-transient","users","useremail","userlogins","usermeta","user_meta","userslugs"]
    Ignored Groups: ["counts","plugins","blog-details","blog-id-cache","blog-lookup","global-posts","networks","rss","sites","site-details","site-lookup","site-options","site-transient","users","useremail","userlogins","usermeta","user_meta","userslugs","themes"]
    

    Here is the error:

    Warning: Redis::connect(): connect() failed: Connection refused in /var/www/html/wp-content/object-cache.php on line 418
    Warning: Cannot modify header information - headers already sent by (output started at /var/www/html/wp-content/object-cache.php:418) in /var/www/html/wp-includes/option.php on line 828
    
    Warning: Cannot modify header information - headers already sent by (output started at /var/www/html/wp-content/object-cache.php:418) in /var/www/html/wp-includes/option.php on line 829
Viewing 9 replies - 1 through 9 (of 9 total)
  • Which port is your Redis installation listening on and which is it mapped to in the container?

    It’s mapped the the default port and yes, it is mapped to the container, hence the command redis-cli works:

    redis-cli -h redis -p 6379
    redis:6379> ping
    PONG

    This is the command running inside the wordpress container. So there is a connection to the redis installation active in the redis container.

    Can you run sudo netstat -lntp in both the host and its container?

    Sure thing, and thank you for your help:

    From the wordpress container:

    bash-4.3# sudo netstat -lntp                                                                                                                       
    Active Internet connections (only servers)
    Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name    
    tcp        0      0 127.0.0.1:9000          0.0.0.0:*               LISTEN      61/php-fpm.conf)
    tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN      62/nginx: master pr
    tcp        0      0 :::80                   :::*                    LISTEN      62/nginx: master pr

    From the host OS (CoreOS)

    Active Internet connections (only servers)
    Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name    
    tcp6       0      0 :::22                   :::*                    LISTEN      1/systemd           
    tcp6       0      0 :::3000                 :::*                    LISTEN      12444/docker-proxy  
    tcp6       0      0 :::443                  :::*                    LISTEN      2142/docker-proxy   
    tcp6       0      0 :::64738                :::*                    LISTEN      10836/docker-proxy  
    tcp6       0      0 :::2376                 :::*                    LISTEN      1/systemd           
    tcp6       0      0 :::2222                 :::*                    LISTEN      12380/docker-proxy  
    tcp6       0      0 :::8080                 :::*                    LISTEN      30383/docker-proxy  
    tcp6       0      0 :::80                   :::*                    LISTEN      2151/docker-proxy   
    

    This is from inside the redis container:

    ctive Internet connections (only servers)
    Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name    
    tcp        0      0 0.0.0.0:6379            0.0.0.0:*               LISTEN      -
    tcp        0      0 :::6379                 :::*                    LISTEN      -

    I just fought through this and discovered that my PHP define('WP_REDIS_HOST', 'redis'); was being added at the wrong time.

    I was using a custom plugin (generated on container creation) to add a few defines. It turns out that this is too late – the defines needed to be in wp-config.php.

    A quick custom PHP file with $r = new Redis(); $r->connect(...) was successful, even though the plugin itself was failing.

    The timing issue was discovered by enabling WP_DEBUG and seeing that the PHP-Redis connection was failing (PHP warning message) on line 418 of wp-content/object-cache.php. After a var_dump($parameters); it became clear that my define()s were not being included early enough as the $parameters object didn’t have my own credentials. This makes sense – as an opcache, plugin behaviour should be included in caching, so the cache needs to be initialized before plugins.

    During this process I disabled the password on the Redis container. Haven’t turned it back on yet, but it should work now…

    Yes, indeed the position of the config lines is crucial.
    I moved them now to just below the SALT and database configurations and it loads without issues.

    Thanks guys for your help 🙂

    Awesome!

    If anyone is curious, my stack is here: https://github.com/emcniece/docker-wordpress

    🙂
    Here is my repo: https://github.com/Gymnae/docker-wordpress

    The little snippet which adds the redis object config cache to wp-config.php

    # sed redis config into config.php
    sed -i "/#@-/a /** redis dropin */\n define( 'WP_REDIS_HOST', 'redis');\n define( 'WP_REDIS_CLIENT', 'pecl');" wp-config.php

    I copied docker-entrypoint.sh and Dockerfile from the original wordpress docker image, but adjusted them to my (baseimages) needs

Viewing 9 replies - 1 through 9 (of 9 total)
  • You must be logged in to reply to this topic.