title: docker-compose: Not able to connect to memcached container
body: <p>I am learning docker. i want to add caching functionality in my application and hence using memcached. below is my docker-compose.yml file</p>
  
  <pre><code>version: "3"
  services:
   app:
     build: .
     volumes: 
      - .:/project 
     command: 'rails s -b 0.0.0.0 -p 3000' 
     container_name: 'test_rails'
     ports:
      - 3000:3000
     depends_on:
       - database
     links:
      - memcached  
   database:
    image: postgres:latest
    volumes:
      - ./data:/var/lib/postgresql/data
    environment:
      POSTGRES_USER: docker-user
      POSTGRES_PASSWORD: docker-password
      POSTGRES_DB: docker-db
   memcached:
    build:
     context: .
     dockerfile: Dockerfile.memcached
    command: 'tail -f /dev/null'
  </code></pre>
  
  <p>when i am trying to connect to memcached server which is inside <code>memcached</code> container from <code>app</code> container using below code </p>
  
  <pre><code>require 'dalli'
  options = { :namespace =&gt; "app_v1", :compress =&gt; true }
  dc = Dalli::Client.new('localhost:11211', options)
  </code></pre>
  
  <p>Then i am getting below error </p>
  
  <pre><code>WARN -- : localhost:11211 failed (count: 0) Errno::EADDRNOTAVAIL: Cannot assign requested address - connect(2) for "localhost" port 11211
  Dalli::RingError: No server available
      from /usr/local/bundle/gems/dalli-2.7.10/lib/dalli/ring.rb:46:in `server_for_key'
      from /usr/local/bundle/gems/dalli-2.7.10/lib/dalli/client.rb:367:in `perform'
      from /usr/local/bundle/gems/dalli-2.7.10/lib/dalli/client.rb:130:in `set'
      from (irb):4
      from /usr/local/bin/irb:11:in `&lt;main&gt;'
  </code></pre>
  
  <p>can someone help me in understanding and resolving this issue.</p>