Linking to a Docker memcached container Linking to a Docker memcached container docker docker

Linking to a Docker memcached container


I think it fails because you're trying to access memcached from the apache container connecting to the localhost of the apache container, while the memcached container is made accessible to the apache one on a different IP address.

This is the line I think is wrong:

$mc->addServer("localhost", 11211);

When you link containers, Docker adds a host entry for the source container to the /etc/hosts file (see the docs about linking).

Therefore you should be able to connect from the apache container to the memcached one using this PHP command:

$mc->addServer("memcached", 11211);

If it doesn't work, check that you can connect to the memcached service from the memcached container itself.