Docker-compose can not connected to the database

Viewed 93

I am new to docker so sorry in advance if this question is going to be stupid or something.

I have a docker-compose.yaml which looks like this:

version: "3.5"
services:
  platform:
    image: memgraph/memgraph-platform:2.0.0
    container_name: memgraph_container
    restart: unless-stopped
    ports:
      - "7687:7687"
  my_app:
    build:
      context: .
      dockerfile: Dockerfile
    container_name: something
    restart: unless-stopped
    command: python main.py
    depends_on:
      - platform
    environment:
      HOST: platform
      PORT: 7687

My code which is responsible to connect to the database is looking like this:

host = os.getenv("HOST")
port = os.getenv("PORT")
conn = mgclient.connect(host=host, port=port)

What those 2 are the commands that I am running

docker-compose up -d
docker-compose exect my_app

So far as I understand this is what it should be done in order for the service my_app to be able to connect to the memgraph database. But something is wrong and I don't get it what.

Here are the logs run by docker-compose logs:

something   | Traceback (most recent call last):
something   |   File "/MemgraphProject/DataBase.py", line 12, in __init__
something   |     self._connection: mgclient.Connection = mgclient.connect(host=host, port=port)
something   | mgclient.OperationalError: couldn't connect to host: Connection refused

My whole component is stuck in a Restarting State for some reason and is not getting out of there:

memgraph_container   /bin/sh -c /usr/bin/superv ...   Restarting        
something            python main.py                   Restarting  

Sometimes if I keep running docker-compose ps I will get memgraph_container State as Up, but is not going to keep that state for long.

#########################################################################################

On the end of the day all what I want to do is to run successfuly my application with docker-compose exec my_app -d but is not working. If I will run docker-compose run my_app to initiate a new container I will get the error message regarding the connection to the database. But if I will run docker-compose exec my_app -d I will receive this error message cause of the Restarting State

Error response from daemon: Container 6fd406ab0b4249424aabd3674aa4572380ac9ddf4f81d756d075bb692c768303 is restarting, wait until the container is running

#########################################################################################

Dose any of you what I am doing wrong and how can I fix this?

0 Answers
Related