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...