Can't connect to python kernel

i am trying to run python script on jupyter using docker compose but can’t connect to python kernel and this is my docker compose file which running on ubuntu vm :

services:
   jupyter:
      container_name: jupyter
      image: jupyter/scipy-notebook
      ports:
         - 8888:8888
      volumes:
         - ./jupyter:/home/jovyan/work
      environment:
         - JUPYTER_TOKEN=password
      command: jupyter notebook --ServerApp.iopub_data_rate_limit=10000000 && ["jupyter", "lab", "--debug"]
      networks:
         testing_net:
            ipv4_address: 172.18.0.3

networks:
    testing_net:
        ipam:
            driver: default
            config:
                - subnet: 172.18.0.2/16` 

and this is my nginx configuration
` location / {
                proxy_set_header   X-Forwarded-For $remote_addr;
                proxy_set_header   Host $http_host;
                proxy_pass         http://localhost:8888;
                proxy_redirect off;
        }```
when i'm trying to run any python code on jupyter can't connect to kernel an it gives me this error in the docker logs 
```[W 2023-10-22 06:55:09.321 ServerApp] Replacing stale connection: ab4cb6a6-12c1-4d60-9730-ec05070a5f5f:56fc3464-cb08-4d4c-8d8b-7962be661691
[W 2023-10-22 06:55:09.322 ServerApp] 400 GET /api/kernels/ab4cb6a6-12c1-4d60-9730-ec05070a5f5f/channels?session_id=56fc3464-cb08-4d4c-8d8b-7962be661691 (1fd5f82f97c944089c5f3113e6ec60a5@172.18.0.1) 1.78ms referer=None```
1 Like

Make sure that the Nginx proxy is configured correctly. The proxy_pass directive should point to the IP address of the Jupyter container, not the hostname. For example, if the Jupyter container is running on the IP address 172.18.0.3, the proxy_pass directive should be proxy_pass http://172.18.0.3:8888;.
Restart the Nginx and Jupyter containers. This will ensure that the proxy is configured correctly and that the Jupyter kernel is running.

The output command

docker-compose ps
docker logs jupyter
nginx -T