1

I am new to rethinkdb and docker compose and have been trying things. But I encountered a problem when trying to run a small data migration project using docker compose. To be more specific, I ran a jupyterlab in a docker container and a rethinkdb in another, I than composed the two. While I can see rethinkdb running at localhost 8080, I can't connect to it from code I copied into my jupyterlab. Here is my code, please help!

---
version: "3.8"
services:
  rethinkdb:
    image: rethinkdb:2.4.4-bookworm-slim
    #build: ./Rethinkdb
    ports: 
      - 8080:8080
      - 28015:28015
      - 29015:29015
  jupyterlab:
    build: ./Python Codes
    #build: ./Jupyterlab
    ports:
      - 8888:8888
    volumes:
      - ./Python Codes:/home/jovyan/work


And here are the code for my jupyterlab:

FROM python:3.9

WORKDIR /app

COPY requirements.txt .

COPY . .

RUN pip install jupyter -U && pip install jupyterlab

RUN apt-get update && apt-get install -y libglib2.0-0 libgl1-mesa-glx && rm -rf /var/lib/apt/lists/*

RUN pip install -r requirements.txt

RUN pip install nodejs

EXPOSE 8888

CMD ["jupyter", "lab","--ip=0.0.0.0", "--no-browser", "--allow-root"]

the code I used to connect to my rethinkdb is:

rethink = r.RethinkDB()
rethink.connect('localhost', 29015).repl()

the error I have received:

---------------------------------------------------------------------------
ConnectionRefusedError                    Traceback (most recent call last)
File /usr/local/lib/python3.9/site-packages/rethinkdb/net.py:349, in SocketWrapper.__init__(self, parent, timeout)
    348 try:
--> 349     self._socket = socket.create_connection((self.host, self.port), timeout)
    350     self._socket.setsockopt(socket.IPPROTO_TCP, socket.TCP_NODELAY, 1)

File /usr/local/lib/python3.9/socket.py:844, in create_connection(address, timeout, source_address)
    843 try:
--> 844     raise err
    845 finally:
    846     # Break explicitly a reference cycle

File /usr/local/lib/python3.9/socket.py:832, in create_connection(address, timeout, source_address)
    831     sock.bind(source_address)
--> 832 sock.connect(sa)
    833 # Break explicitly a reference cycle

ConnectionRefusedError: [Errno 111] Connection refused

During handling of the above exception, another exception occurred:

ReqlDriverError                           Traceback (most recent call last)
Cell In[3], line 2
      1 rethink = r.RethinkDB()
----> 2 rethink.connect('localhost', 28015).repl()

File /usr/local/lib/python3.9/site-packages/rethinkdb/__init__.py:90, in RethinkDB.connect(self, *args, **kwargs)
     89 def connect(self, *args, **kwargs):
---> 90     return self.make_connection(self.connection_type, *args, **kwargs)

File /usr/local/lib/python3.9/site-packages/rethinkdb/net.py:830, in make_connection(connection_type, host, port, db, auth_key, user, password, timeout, ssl, url, _handshake_version, **kwargs)
    816     password = None
    818 conn = connection_type(
    819     host,
    820     port,
   (...)
    828     **kwargs
    829 )
--> 830 return conn.reconnect(timeout=timeout)

File /usr/local/lib/python3.9/site-packages/rethinkdb/net.py:696, in Connection.reconnect(self, noreply_wait, timeout)
    693 self.close(noreply_wait)
    695 self._instance = self._conn_type(self, **self._child_kwargs)
--> 696 return self._instance.connect(timeout)

File /usr/local/lib/python3.9/site-packages/rethinkdb/net.py:538, in ConnectionInstance.connect(self, timeout)
    537 def connect(self, timeout):
--> 538     self._socket = SocketWrapper(self, timeout)
    539     return self._parent

File /usr/local/lib/python3.9/site-packages/rethinkdb/net.py:437, in SocketWrapper.__init__(self, parent, timeout)
    435 except Exception as ex:
    436     self.close()
--> 437     raise ReqlDriverError(
    438         "Could not connect to %s:%s. Error: %s"
    439         % (self.host, self.port, str(ex))
    440     )

ReqlDriverError: Could not connect to localhost:28015. Error: [Errno 111] Connection refused

Please help, thank you very much!

I tried both port 29015 and 28015. I have also tried to run the jupyter/minimal-notebook instead of the self constructed jupyterlab, but when I tried this, I can not ran my code when I copied into the jupyterlab. I suspect it's something to do with my jupyter, but I might be wrong...

1 Answer 1

0

Here is your issue: rethink.connect('localhost', 28015).repl(). You should try with rethink.connect('rethinkdb', 28015).repl()

When running inside containers, each container typically has its own isolated network namespace. This means that "localhost" within a container refers to the container itself, not the host machine or other containers. So jupyterlab application can't view rethinkdb service because 28015 port is exposed to your own local machine and visible from your own localhost but not from the container.

By default Docker Compose you are using sets up a single network for your app. Each container for a service joins the default network and is both reachable by other containers on that network, and discoverable by the service's name. (https://docs.docker.com/compose/networking/)

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.