我在docker-compose中遇到memcached问题。这是docker-compose.yml:
nginx:
container_name: nginx
image: nginx:latest
ports:
- 127.0.0.2:8000:80
volumes:
- ./htdocs:/htdocs
- ./nginx.conf:/etc/nginx/conf.d/nginx.conf
links:
- php
php:
container_name: php
build: ./php
volumes:
- ./htdocs:/htdocs
- ./php/php.ini:/usr/local/etc/php/php.ini
links:
- mysql
- memcached
mysql:
container_name: mysql
image: mysql:latest
ports:
- 127.0.0.2:8001:3306
volumes:
- ./my.cnf:/etc/mysql/my.cnf
- ./db:/var/lib/mysql
environment:
- MYSQL_ROOT_PASSWORD=root
- MYSQL_DATABASE=db
- MYSQL_USER=root
- MYSQL_PASSWORD=root
memcached:
container_name: memcached
image: memcached:latest
ports:
- "11211:11211"
这是我的PHP代码:
error_reporting(E_ALL & ~E_NOTICE);
$memcached = new Memcached;
$memcached->addServer('0.0.0.0', 11211);
echo '<pre>'; print_r($memcached->getServerList()); echo '</pre>';
if($memcached->getStats() === false) {
echo 'returned false';
} else {
echo '<pre>'; print_r($memcached->getStats()); echo '</pre>';
}
结果是:
Array
(
[0] => Array
(
[host] => 0.0.0.0
[port] => 11211
[type] => TCP
)
)
returned false
为什么memcached无法看到服务器? (getStats什么都没有返回)命令&#34; docker ps&#34;返回列表,它运行docker memcached:lastest as port&#34; 0.0.0.0:11211-&gt; 11211 / tcp&#34;。对不起我的英语不好。