【问题标题】:Redis as session storage for WordPress in dockerRedis 作为 Docker 中 WordPress 的会话存储
【发布时间】:2016-11-11 23:53:16
【问题描述】:

我一直在尝试在 docker 中将 Redis 与 WordPress 链接一段时间,但我似乎无法让它工作。

这是我的 Dockerfile:

FROM wordpress:latest

ENV PHPREDIS_VERSION 2.2.8

 RUN apt-get update && apt-get install -yqq unzip git php5-redis
 RUN curl -L -o /tmp/redis.tar.gz https://github.com/phpredis/phpredis/archive/$PHPREDIS_VERSION.tar.gz \
    && tar xfz /tmp/redis.tar.gz \
    && rm -r /tmp/redis.tar.gz \
    && mv phpredis-$PHPREDIS_VERSION /usr/src/php/ext/redis \
    && docker-php-ext-install redis

RUN { \
    echo 'session.save_handler = redis'; \
    echo 'session.save_path = redis:6379'; \
} >> /usr/local/etc/php/conf.d/docker-php-ext-redis.ini

RUN curl -o /tmp/composer.phar http://getcomposer.org/composer.phar \
  && mv /tmp/composer.phar /usr/local/bin/composer
RUN curl -o /tmp/markdown.zip https://littoral.michelf.ca/code/php-markdown/php-markdown-extra-1.2.8.zip \
  && unzip /tmp/markdown.zip -d /usr/src/wordpress/wp-content/plugins

RUN git clone https://github.com/Otto42/simple-twitter-connect.git /usr/share/wordpress/wp-content/plugins/simple-twitter-connect

RUN rm -rf /tmp/stc.zip && rm -rf /tmp/stc && rm -rf /tmp/markdown.zip

ADD etc/composer.json /usr/src/composer.json

RUN chmod a+x /usr/local/bin/composer
RUN cd /usr/src/ && /usr/local/bin/composer install
RUN chmod -R a+rX /usr/src/wordpress

RUN curl -o /tmp/twentyeleven.zip https://downloads.wordpress.org/theme/twentyeleven.2.4.zip
RUN unzip /tmp/twentyeleven.zip -d /usr/src/wordpress/wp-content/themes/
RUN rm -rf /tmp/twentyeleven.zip && rm -rf /tmp/dataporten-oauth.zip

COPY feidernd /usr/src/wordpress/wp-content/themes/feidernd
COPY wp-redis-user-session-storage.php /usr/src/wordpress/wp-content/plugins/wp-redis-user-session-storage.php

VOLUME volume/ /var/www/

我正在链接两个容器

$ docker run -p 6379:6379 --name redis redis
$ docker run -p 80:80 --link redis:redis --env-file=env.list -t testbuild

我尝试从 Pantheon (https://github.com/pantheon-systems/wp-native-php-sessions) 安装 Native-PHP-Sessions 插件,但没有成功。

任何人对如何让两者正确链接有一些好的建议?

【问题讨论】:

  • 从您发布的内容中很难判断发生了什么。您是否通过docker exec ... 验证了redis 是否正常工作?同样的,你可以docker exec进入WP容器和redis通信吗? (您可能需要在 WP 容器上 apt-get install redis-tools。)另外,我会考虑将您的 WP 文件外部化,这样您就不会进行如此复杂的构建,但这是另一回事。

标签: php wordpress session docker redis


【解决方案1】:

改用 docker-compose 文件。然后进行验证,尝试从您的 wordpress 容器中执行 curl 以检查它们是否已链接。

您认为它们没有正确链接的原因是什么?

https://docs.docker.com/compose/

【讨论】:

  • 可能是 redis 配置不正确,因为我在运行 curl redis:6379 时得到一个恒定的负载,并且没有答案。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2019-05-13
  • 1970-01-01
  • 2014-09-28
  • 2014-05-20
  • 2020-05-31
  • 1970-01-01
  • 2012-09-25
相关资源
最近更新 更多