Docker Redis database cache configuration (WordPress)
network environment
preparation in advance
$docker pull redis
Configure and start Redis container
-
Create configuration file and directory
Create Redis required directory: mkdir ~/conf mkdir -p ~/data/redis_data Clone Default Profile redis.conf : #Www.azimiao.com Zimiao haunt blog cd ~/conf wget https://raw.githubusercontent.com/redis/redis/unstable/redis.conf On demand configuration redis.conf 。 For example, add a connection password: Requirepass mypassword//Cancel the previous # and modify the password text -
Start Container
Start the Redis container and map the configuration file and data directory: #Blog www.azimiao.com docker run -itd \ --name redis_server1 \ -v /home/yetu/conf/redis.conf:/etc/redis.conf \ -v /home/yetu/data/redisdata:/data \ --network blog_default \ --restart=always redis redis-server /etc/redis.conf Command resolution: -v /home/yetu/conf/redis.conf:/etc/redis.conf : Map Profile -v /home/yetu/data/redis_data:/data : Map Data File --network blog_default : Join the blog_default network redis-server /etc/redis.conf : Use the configuration file to start the redis server in the container
Then in the php container, you can ping the redis_server1 : #ping redis_server1 PING redis_server1 (172.18.0.4): 56 data bytes 64 bytes from 172.18.0.4: seq=0 ttl=64 time=0.177 ms 64 bytes from 172.18.0.4: seq=1 ttl=64 time=0.181 ms 64 bytes from 172.18.0.4: seq=2 ttl=64 time=0.162 ms
Configure PHP
<? php echo phpinfo(); ?>
# docker exec -it php /bin/sh # install-php-extensions redis #Press ctrl+p+q to exit
Configure WordPress
define("WP_REDIS_HOST","redis_server1");// Host name (Docker container name) define("WP_REDIS_PORT",6379);// Port (6379 for configuration file by default) define("WP_REDIS_PASSWORD","yourpassword");// Password (if any) #Other parameter references: https://github.com/rhubarbgroup/redis-cache/wiki/Connection-Parameters
other