Ubuntu - Docker - Nginx / PHP / MySql
http://jasonmun.blogspot.my/2016/05/ubuntu-docker-nginx-php-mysql.html
在弄 php-fpm-mysql 镜像的时候,
Dockerfile 文件中添加安装 memcached 模块
\
&& apt-get install -y libmemcached-dev \
&& pecl install memcached \
&& docker-php-ext-enable memcached
https://hub.docker.com/_/memcached
# 启动容器
$ docker run --name memcached-ct -d -p 11211:11211 memcached:1.4.25
# 如果是之后添加的, php-fpm-mod 和 nginx_server 都要撤除与重启
$ docker stop php-fpm-mod
$ docker rm php-fpm-mod
$ docker run --name php-fpm-mod --volumes-from wwwroot --link mysql_server:mysql -d php-fpm-mysql
$ docker stop nginx_server
$ docker rm nginx_server
$ docker run --name=nginx_server --volumes-from wwwroot --link php-fpm-mod:php -p 80:80 -d nginx-fix
# 进入容器 php-fpm-mod 中
$ docker exec -it php-fpm-mod bash
$ php -m # 可以找到 memcached 模块
# 测试
$ telnet 192.168.247.128 11211
Trying 192.168.247.128...
Connected to 192.168.247.128.
Escape character is '^]'.
set id 0 0 4
1234
STORED
get id
VALUE id 0 4
1234
END
quit
PHP 代码
<?php
$memcache = new Memcache;
$memcache->connect("192.168.247.128",11211);
echo "Server's version: " . $memcache->getVersion() . "<br />\n";
$testArray = array('horse', 'cow', 'pig');
$tmp = serialize($testArray);
$memcache->add("key", $tmp, 30);
echo "Data from the cache:<br />\n";
print_r(unserialize($memcache->get("key")));
?>
没有评论:
发表评论