title: Linking Django and Postgresql with Docker
body: <p>I have two Docker containers. The first one is Postgresql container, which I run using the following command.</p>
  
  <pre><code>sudo docker run -v /home/mpmsp/project/ezdict/postgresql/data:/var/lib/postgresql/data -p 127.0.0.1:5432:5432  -name my-postgres -d postgres
  </code></pre>
  
  <p>It is based on <a href="https://registry.hub.docker.com/_/postgres/">official image</a> and it is working perfectly, I can connect to Postgresql from the host.</p>
  
  <p>The second container is a container with my Django application. The image is built using the following Dockerfile (based on <a href="https://registry.hub.docker.com/_/python/">this image</a>):</p>
  
  <pre><code>FROM python:3-onbuild
  EXPOSE 8000 5432
  CMD ["/bin/bash"]
  </code></pre>
  
  <p>And I run this container with the following command</p>
  
  <pre><code>sudo docker run --link my-postgres:my-postgres -v /home/mpmsp/project/ezdict/ezbkend:/usr/src/app -name my-app -i -t my-app
  </code></pre>
  
  <p>docker ps output shows that containers are linked</p>
  
  <pre><code>NAMES
  my-app/my-postgres, my-postgres
  </code></pre>
  
  <p>However, when I go to localhost:8000, I see an error page from Django, with the following output</p>
  
  <pre><code>OperationalError at /api-auth/login/
  could not connect to server: Connection refused
      Is the server running on host "127.0.0.1" and accepting
      TCP/IP connections on port 5432?
  Request Method: GET
  Request URL:    http://127.0.0.1:8000/api-auth/login/
  Django Version: 1.6.4
  Exception Type: OperationalError
  Exception Value:    
  could not connect to server: Connection refused
      Is the server running on host "127.0.0.1" and accepting
      TCP/IP connections on port 5432?
  Exception Location: /usr/local/lib/python3.4/site-packages/psycopg2/__init__.py in     connect, line 164
  Python Executable:  /usr/local/bin/python
  Python Version: 3.4.1
  Python Path:    
  ['/usr/src/app',
   '/usr/local/lib/python34.zip',
   '/usr/local/lib/python3.4',
   '/usr/local/lib/python3.4/plat-linux',
   '/usr/local/lib/python3.4/lib-dynload',
   '/root/.local/lib/python3.4/site-packages',
   '/usr/local/lib/python3.4/site-packages']
  Server time:    Птн, 10 Окт 2014 12:07:07 +0400
  </code></pre>
  
  <p>Application's settings.py</p>
  
  <pre><code>  DATABASES = {
     'default': {
         'ENGINE': 'django.db.backends.postgresql_psycopg2',
         'NAME': 'mydb',                      
         'USER': 'postgres',
         'PASSWORD': '',
         'HOST': '127.0.0.1',                      
         'PORT': '5432',                      
      }
    }
  </code></pre>
  
  <p>How to make linking work? Thanks in advance</p>