Blog Entry
试一下dotnet-interactive
试一下dotnet-interactive
- Created
- 2022/04/21
- Updated
- 2022/04/21
in VSCode
in Docker
文件结构
.├─ Dockerfile├─ docker-compose.yml└─ conf └─ jupyter_lab_config.py 配置文件Dockfile
根据这个Dockfile修改
FROM mcr.microsoft.com/dotnet/sdk:6.0-focal
ARG HTTP_PORT_RANGE=1100-1200
# Opt out of telemetry until after we install jupyter when building the image, this prevents caching of machine idENV DOTNET_INTERACTIVE_CLI_TELEMETRY_OPTOUT=true
# Install all OS dependencies for notebook server that starts but lacks all# features (e.g., download as all possible file formats)
ENV DEBIAN_FRONTEND noninteractiveRUN apt-get update \ && apt-get install -yq --no-install-recommends \ wget \ bzip2 \ ca-certificates \ sudo \ locales \ fonts-liberation \ run-one \ python3.8 \ python3-pip \ && apt-get clean && rm -rf /var/lib/apt/lists/*
RUN echo "en_US.UTF-8 UTF-8" > /etc/locale.gen && \ locale-gen
RUN python3 -m pip install setuptoolsRUN python3 -m pip install jupyterRUN python3 -m pip install jupyterlab
# Add package sourcesRUN dotnet nuget add source "https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet-tools/nuget/v3/index.json" -n "dotnet-tools"RUN dotnet nuget add source "https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet5/nuget/v3/index.json" -n "dotnet5"RUN dotnet nuget add source "https://pkgs.dev.azure.com/dnceng/public/_packaging/MachineLearning/nuget/v3/index.json" -n "MachineLearning"
# Install lastest build from master branch of Microsoft.DotNet.InteractiveRUN dotnet tool install --tool-path /usr/share/dotnet-interactive Microsoft.dotnet-interactive --add-source "https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet-tools/nuget/v3/index.json"RUN ln -s /usr/share/dotnet-interactive/dotnet-interactive /usr/bin/dotnet-interactiveRUN dotnet interactive jupyter install --http-port-range ${HTTP_PORT_RANGE}
# Enable telemetry once we install jupyter for the imageENV DOTNET_INTERACTIVE_CLI_TELEMETRY_OPTOUT=false
EXPOSE 8888EXPOSE ${HTTP_PORT_RANGE}
RUN mkdir notebooks
WORKDIR notebooks
ENTRYPOINT jupyter lab --ip=0.0.0.0 --allow-root --notebook-dir=/notebooks/docker-compose
version: '3'
services: dotnet-interactive: # image: xkyii/dotnet-interactive build: . volumes: - ~/data/notebooks:/notebooks - ./conf/:/conf ports: - 8888:8888 entrypoint: - jupyter-lab command: --config=/conf/jupyter_lab_config.py # 写到配置文件里面了 # --no-browser # --ip=0.0.0.0 # --allow-root # --notebook-dir=/notebooks/配置
# 启动时不打开浏览器c.LabApp.open_browser = False# 允许域名(nginx反代需要)c.ServerApp.allow_origin = '*'# 允许远程访问(nginx反代需要)c.ServerApp.allow_remote_access = True# 以root运行(Docker传统技能)c.ServerApp.allow_root = True# 监听ipc.ServerApp.ip = '0.0.0.0'# 登录密码c.ServerApp.password = '...'关于密码:
jupyter-lab passwordEnter password: Verify password: [JupyterPasswordApp] Wrote hashed password to /root/.jupyter/jupyter_server_config.json
cat /root/.jupyter/jupyter_server_config.json{ "ServerApp": { "password": "argon2:$argon2id$v=19$m=10240,t=10,p=8$5gG0gJSC4x2lu0Z7jPJU/A$F9zX+C+jfVFc8ixxrTAonS/ioGjGG6oHJgXP/iRwkX4" }}将ServerApp.password的内容复制填充到jupyter_lab_config.py的c.ServerApp.password字段就可以了
启动
docker-compose up -d
# 如果启动有问题,可以用这个看日志# 建议首次启动时用这个,毕竟构建docker镜像过程还挺不稳定的docker-compose up访问
启动成功的话应该就可以访问了: http://your-ip:8888
nginx代理
server { # 监听端口 listen 80; # 域名 server_name notebook.xkyii.cn; # Proxy location / { proxy_pass http://127.0.0.1:8888/; proxy_http_version 1.1; proxy_redirect off; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Proto $scheme; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection "upgrade";
proxy_read_timeout 600s; proxy_send_timeout 600s; }}后面就可以用域名访问了