How to host a Jupyter notebook in your Ubuntu 18.04 or 20.04 server using docker-compose

jupyter-notebook devopedia

Table of Contents

To host a Jupyter notebook in your Ubuntu 8.04 or 20.04 server so it can be accessible from everywhere run the following commands:

1.First install docker and docker-compose on your server (link).

2.Create a data-science directory and create a docker-compose.yaml file.

mkdir data-science
cd data-science
nano docker-compose.yaml

Inside docker-compose.yaml paste the following:

#docker-compose.yaml
services:
  jupyter:
    user: root
    image: jupyter/scipy-notebook:python-3.9
    container_name: jupyter-notebook
    volumes:
      - ./notebooks:/home/justdataplease
    ports:
      - "80:8888"
    environment:
      - NB_USER=justdataplease
      - NB_GID=1000
      - JUPYTER_ENABLE_LAB=yes
      - JUPYTER_TOKEN=4321
      - CHOWN_HOME=yes
      - CHOWN_HOME_OPTS=-R
    restart: always

3.Finally run the following command:

docker-compose up -d

4.Access your notebook by visiting the following url:

http://<server_public_ip>/lab?token=<your_token>

You can also run in another port defined in docker-compose.yaml (i.e - "5000:8888" ) Then to access your notebook by visiting the following url:

http://<server_public_ip>:5000/lab?token=<your_token>