Docker compose安装部署jupyter lab并绑定二级域名

narcissuskid
发布于 2023-08-07 / 272 阅读 / 0 评论 / 0 点赞

Docker compose安装部署jupyter lab并绑定二级域名

前置条件

操作步骤

Cloudflare配置子域名

DNS->Add record增加一条新纪录

TypeNameContent
CNAME子域名主域名

通过ping 子域名.主域名检查是否配置成功(修改Cloudflare后需要等一段时间才能生效)

Docker compose安装部署jupyter lab

  1. 新建jupyter目录,此处以/home/ubuntu/jupyter为例
mkdir jupyter
cd jupyter
  1. 在目录中新建.jupyter文件,并修改读写权限
mkdir .jupyter
chmod -R 777 .jupyter
  1. 新建docker-compose.yaml文件
version: '3.1'
services:
  jellyfin:
    image: jupyter/scipy-notebook:latest
    restart: "unless-stopped"
    container_name: jupyter
    ports:
      - 8888:8888 #映射宿主机端口:容器端口
    environment:
      - "JUPYTER_ENABLE_LAB=yes"
      - "RESTARTABLE=yes"
    command: ["start-notebook.sh", "--NotebookApp.allow_origin='*'"]
    volumes:
      - /home/ubuntu/jupyter:/home/jovyan/work #映射宿主机工作目录:容器工作目录
      - /home/ubuntu/jupyter/.jupyter:/home/jovyan/.jupyter #映射宿主机根目录:容器根目录
      - /usr/local/nginx/etc/cert:/etc/nginx/cert #映射宿主机认证文件目录:容器认证文件目录
  1. 修改jupyter默认配置,打开/home/ubuntu/jupyter/.jupyter/jupyter_server_config.py修改如下内容:
c.ServerApp.allow_origin = '*'
c.ServerApp.allow_remote_access = True
c.ServerApp.certfile = '/etc/nginx/cert/cert.pem' #容器中SSL认证文件路径
c.ServerApp.keyfile = '/etc/nginx/cert/key.pem' #容器中SSL密钥文件路径
  1. 安装部署
 docker compose up -d

使用docker ps检查STATUS是否为healthy

安装部署Nginx

  1. Docker compose安装
  2. 修改nginx配置:
map $http_upgrade $connection_upgrade {
    default upgrade;
    '' close;
}
upstream jupyter {
  server 宿主机IP:宿主机端口;
}
server {

listen 443 ssl;
listen [::]:443 ssl;
server_name 二级域名;
ssl_certificate /etc/nginx/cert/cert.pem;  # nginx容器中SSL认证文件路径
ssl_certificate_key /etc/nginx/cert/key.pem; # nginx容器中SSL密钥文件路径
ssl_client_certificate /etc/nginx/cert/cloudflare.crt; # nginx容器中Cloudflare源认证拉取文件路径

location / {

    proxy_pass https://jupyter;
    proxy_set_header HOST $host;
    proxy_set_header X-Forwarded-Proto $scheme;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header X-NginX-Proxy true;
    auth_basic "Restricted Content";

    # WebSocket support
    proxy_http_version 1.1;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection $connection_upgrade;
    proxy_set_header Origin "";
    proxy_read_timeout 86400;
  }
}
  1. 安装部署
 docker compose up -d

Done


评论