Can't connect to Redis/Memcache from inside Docker Container

I have a Docker Image which encapsulates all the tools for our dev environment. However, running the application in certain profiles will attempt to connect to external Redis/Memcache servers.

However, it can’t establish a connection with these servers. When pinging inside the container, it finds the correct IP for the host but it says the host is unreachable:

  • Running a cucumber test on firefox in a docker container
  • Ansible docker_container etc_hosts with variable key
  • Compose: running a container that exits
  • docker: Error response from daemon: client is newer than server
  • Can I use LXD image to create Docker container and/or vice versa?
  • Connect to MySQL server from php with Docker
  • ping HOST
    PING HOST (CORRECT.IP) 56(84) bytes of data.
    From e856591c01e7 (172.17.0.3) icmp_seq=1 Destination Host Unreachable
    From e856591c01e7 (172.17.0.3) icmp_seq=2 Destination Host Unreachable
    From e856591c01e7 (172.17.0.3) icmp_seq=3 Destination Host Unreachable
    From e856591c01e7 (172.17.0.3) icmp_seq=4 Destination Host Unreachable
    From e856591c01e7 (172.17.0.3) icmp_seq=5 Destination Host Unreachable
    From e856591c01e7 (172.17.0.3) icmp_seq=6 Destination Host Unreachable
    

    pinging or curling other sites, such as google or facebook, work completely fine.

    DockerMachine is the default as are the network settings. Running on Mac OSX 10.10.5, Docker 1.12.1, Docker-Machine 0.8.1

    Any ideas? I’m at a loss.

  • Running Asterisk and it's mysql database in different docker containers
  • How to cleanup docker?
  • How to connect postgresql container to django container?
  • How to change owner of Docker for Windows
  • Redis sentinel docker image / Dockerfile
  • How to get the docker container logs using docker-java client library
  • 4 Solutions collect form web for “Can't connect to Redis/Memcache from inside Docker Container”

    Docker is using different network modes. You could try to run your container in “Host Network”, so it will share the network connections with the host running docker-machine:

     docker run --net=host your_image and other options
    

    What is the output of docker ps and how did you run the container?

    For anyone having this problem in the future, try making a docker network with ipv6 and the ports open. I didn’t get it working but I’m fairly certain that is the right path.

    If the possible solutions above don’t work. Maybe you should check memcache server config for listened IP addresses.

    Is memcache machine another docker container or a seperate standalone server for memcache?

    If you wish to connect to the host machine’s memcache server, you may need to configure memcache to allow connections from IP addresses other than local IP.

    If you are using ubuntu (or similar) edit config with ;

    nano /etc/memcached.conf
    

    and find the line starting with “-l 127.0.0.1” add your client machines IP addresses by separating them with commas.

    For instance if you want to connect from 172.17.0.3 and 172.18.0.3 you replace with ;

    -l 127.0.0.1,172.17.0.1,172.18.0.1
    
    Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.