Docker exposed port is already in use

I’m running jupyter hub within docker. I have mapped two ports to the host machine. One for jupyter and one where I wish to serve the panel app on. Following is my docker-compose.yml file

services:
  jupyter_hub:
    image: jupyter_hub:personal
    build:
      context: .
      dockerfile: Dockerfile
    container_name: jupyter_hub
    ports:
      - "20010:8000"
      - "20011:8001"
    volumes:
      - jupyter_hub_etc_volume:/etc
      - jupyter_hub_home_volume:/home
      - jupyter_hub_vhagar_volume:/personal
    restart: always

The docker start up perfectly well but when I go to sere the Panel dashboard application on port 20011. It says its already in use. The jupyterhub server is correctly mapped to port 20010. Here’s the error message:

Cannot start Bokeh server, port 8001 is already in use

And the following is the result of netstat -tulpn

tcp        0      0 127.0.0.1:8001          0.0.0.0:*               LISTEN      11/node
tcp6       0      0 :::8000                 :::*                    LISTEN      11/node

How can I serve my Panel applcation ?

You mean when you go “see” the panel dashboard? This seems to be something appliation specific. Normally you would get the error message when you start the container, not when you try to access a port. And since the port in the error message is an internal port which is inside the container, it couldn’t have an already used port.

I recommend searching for “cannot start bokeh server” on the internet so you can find similar issues like this

Thanks for the reply @rimelek. I think I wasn’t clear.
From the jupyter_hub docker contianer I run the following command:

panel serve --port 8001 panel_app.py

This is when I get the error message
Cannot start Bokeh server, port 8001 is already in use
I do not know how or why this is already in use.

I don’t know. I never run that command in Jupyter Hub. I guess you already ran it once and the service is still running. Or there is another internal service using that port. Containers have network isolation, so if the command says the port is used, it is used inside the container. Unless of course you use the host network or the network of another container (shared network namespace like in Kubernetes pods) , but that is not set in your shared compose file.

I was able to get this to work. I specified three ports. The two ports were being used by node and third was available for me to serve my application from within docker