1

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?

KWriter
  • 1,024
  • 4
  • 22
Mircea
  • 1,671
  • 7
  • 25
  • 41
  • Might want to look at: https://memgraph.com/blog/graph-web-application They actually have MEMGRAPH_PORT = int(os.getenv("MEMGRAPH_PORT", "7687")). Not sure using int makes a difference, but they give some examples there. – SScotti Jan 07 '22 at 02:03
  • Your memgraph-platform image seems to be running a console in its default command. From my tries inside docker at the moment, it won't stay up unless you start it interactively (i.e. with the `-it` flag). This strongly suggest that it will not stay up with docker-compose unless you add the option `tty: true` to your service in your compose file. Your app container won't be able to connect to it unless the container stay up and started. – Zeitounator Jan 07 '22 at 02:10
  • That was my issue, thanks @Zeitounator for this. Now everything is working as it should :D – Mircea Jan 07 '22 at 09:50

0 Answers0