Discussion Forum

Unable to connect to TypeDB Server in Docker Container

I’m trying to connect to a TypeDB server running in a container and I get the following error.

typedb.common.exception.TypeDBClientException: Client Error: Unable to connect to TypeDB server.

I’m not sure why this is not working.

Here are my files:

Dockerfile

FROM python:3.8-slim-buster
COPY . ./app
COPY app.py /app
USER root
RUN pip install typedb-client

docker-compose.yml

version: "3.4"

services:
  typedb:
    container_name: typedb
    image: vaticle/typedb:latest
    ports:
      - 1729:1729
  python:
    container_name: python
    build: .
    depends_on:
      - "typedb"
    command: bash -c "python app/app.py"

app.py

from typedb.client import TypeDB
import os

# give server time to come up
os.system('sleep 2')

db_name = 'ct1'
with TypeDB.core_client("0.0.0.0:1729") as client:
  if not client.databases().contains(db_name):
    client.databases().create(db_name)

Can you see the TypeDB Server running via the log output somewhere?
Have you tried a longer sleep just in case it takes a little longer to come up? Also with localhost instead of 0.0.0.0?

Can you see the TypeDB Server running via the log output somewhere?

Yes. In fact, if I run the python script outside of the container, it will connect to the TypeDB server running in the container.

Have you tried a longer sleep just in case it takes a little longer to come up?

Yes, up to 10s

Also with localhost instead of 0.0.0.0 ?

Yes. Same result.

If you copy the files and run docker-compose up you can recreate this.

According to Docker Compose’s docs, try replacing the address with the container name, which in this case is typedb:

with TypeDB.core_client("typedb:1729") as client:
1 Like

Thank you!

Extra thanks for going out of your way to provide docker support in the Typedb forum :laughing:

We provide everything! :rofl:

1 Like