# Postgres container refusing connections

**URL:** <https://forums.docker.com/t/postgres-container-refusing-connections/102819>\
**Category:** Compose\
**Created:** [January 8, 2021, 4:36pm UTC](https://forums.docker.com/t/postgres-container-refusing-connections/102819 "2021-01-08T16:36:43Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![zhine3](https://avatars.discourse-cdn.com/v4/letter/z/f07891/32.png) [@zhine3](https://forums.docker.com/u/zhine3)\
**Post date:** [January 8, 2021, 4:36pm UTC](https://forums.docker.com/t/postgres-container-refusing-connections/102819/1 "2021-01-08T16:36:43Z")

</div>

Hi everyone, I’m very new to Docker and running into an issue: I have two containers that I am running with docker-compose - one is a python app, the other a postgres container that has the data I’m analyzing with the app. I can get them both up and running but when connecting to the postgres database, I receive the following error:  
psycopg2.OperationalError: could not connect to server: Connection refused  
Is the server running on host “db” (172.30.0.2) and accepting  
TCP/IP connections on port 8000?  
However, using the command line, I CAN successfully connect to the database using

```bash
psql -U postgres -h 172.30.0.2 -p 8000 -d mydb

```

Is there an reason why I can’t connect from the other docker container?  
Here is the yaml file I’m using for the containers

```auto
version: "3.9"
services:
  db:
    image: postgres
    environment:
      POSTGRES_PASSWORD: "docker"
    ports:
      - "8000:5432"
    volumes:
      - ./init.sh:/docker-entrypoint-initdb.d/init.sh
      - ./data_store/data.sql:/tmp/psql_data/data.sql
    tty: true
    stdin_open: true

  app:
    build: .
    ports:
      - "8081:8080"
    depends_on:
      - db
    links:
      - db
    stdin_open: true
    tty: true

```

And the connection code in python is

```python
params = {'host':'db','port':'8000','database':'mydb', 'user':'postgres', 'password':'docker'}
psycopg2.connect(**params)
```
