jupyter-server-proxy icon indicating copy to clipboard operation
jupyter-server-proxy copied to clipboard

Proxying services on a named docker-compose network

Open psychemedia opened this issue 5 years ago • 2 comments

If we run a Jupyter notebook server in a docker container and docker-compose with another application (eg OpenRefine) running a separate container, eg with a docker-compose script along the lines of:

version: '3.5'

services:
  refine:
    container_name: refine_container
    image: psychemedia/openrefinedemo
    # Let the jupyter server proxy expose the port
    #internal port 3333 is available on jupyternet as http://refine_container:3333
    #ports:
    #  - "3333:3333"
    networks:
      - jupyternet
    restart: unless-stopped

  jupyter:
    container_name: jupyter_notebook_container
    #image: jupyter/minimal-notebook
    build: ./
    environment:
      JUPYTER_TOKEN: 'letmein'
    ports:
      - "80:8888"
    networks:
      - jupyternet
    volumes:
      - ./jupyter_notebook_config.py:/home/jovyan/.jupyter/jupyter_notebook_config.py
    restart: unless-stopped

networks:
  jupyternet:
    driver: bridge

build a notebook sever container with the server proxy package installed:

FROM jupyter/minimal-notebook

RUN pip install git+https://github.com/jupyterhub/jupyter-server-proxy

and mounting a traitlet config file along the lines of:

c.ServerProxy.servers = {
    'openrefine': {
        #I don't need a command, server is already running?
        #'command': ['/home/jovyan/.openrefine/openrefine-2.8/refine', '-p', '{port}','-d','/home/jovyan/openrefine'],
        #Can we specify network: http://refine_container
        'port': 3333,
        'timeout': 120,
        'launcher_entry': {
            'title': 'OpenRefine'
        },
    },
}

is there a way of:

  • specifying that the service we want to proxy is on http://refine_container:3333 (which is available over jupyternet);
  • avoiding the start command (because the service we want to proxy is already free running in the connected container.

I guess another way to do it would be just to build OpenRefine into the notebook container and then letting the traitlet handle starting OpenRefine; but it would open up more possibilities in general if we could just compose the OpenRefine container in? [UPDATE: example]

psychemedia avatar Feb 11 '19 23:02 psychemedia

Technically it should be easy, just make the host configurable: https://github.com/jupyterhub/jupyter-server-proxy/blob/8f0799d706011dd6c56670286a6df566f9448c13/jupyter_server_proxy/handlers.py#L153, and it would also be easy to not start the process.

However that allows someone to configure jupyter-server-proxy to behave as a general proxy, i.e. it can proxy any internal host and service. You could do that anyway since you can do anything in Python, but should it be supported by jupyter-server-proxy?

manics avatar Feb 12 '19 14:02 manics

@manics I have started looking at various ways of using Jupyter notebook auth and jupyter server proxy as a way of providing auth to other apps. It's often easier to link in other apps as other docker images. Adding nginx as the proxy is one way to handle it, but that makes it more complex for the user.

I realise I am probably an outlier but the vision I work to is someone who isn't a sysadmin but who may want to pull workbenches together comprising several apps; to a certain extent, docker-compose makes that tractable.

Setting up nginx is one more thing to have to know about (and if I'm a researcher in an NGO or a freelance or local press data journalist, that's an overhead I'd rather not worry about): much easier to just use the notebook server as my proxy?

psychemedia avatar Feb 12 '19 16:02 psychemedia