背景介绍

在之前的文章 - 交互式 .Net 中已经介绍了什么是交互式 .Net,文中是通过 Visual Studio Code 插件的方式实现交互式 .Net 的。现在,我们将使用容器的方式实现交互式 .Net。

镜像构建

1. Dockerfile

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 id
ENV 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 noninteractive
RUN sed -i 's|https\?://[^/]\+/|http://mirrors.aliyun.com/|' /etc/apt/sources.list
RUN 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 setuptools
RUN python3 -m pip install jupyter
RUN python3 -m pip install jupyterlab # Add package sources
RUN 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/dotnet6/nuget/v3/index.json" -n "dotnet6"
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.Interactive
RUN 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-interactive
RUN dotnet interactive jupyter install --http-port-range ${HTTP_PORT_RANGE} # Enable telemetry once we install jupyter for the image
ENV DOTNET_INTERACTIVE_CLI_TELEMETRY_OPTOUT=false EXPOSE 8888
EXPOSE ${HTTP_PORT_RANGE} RUN groupadd -g 1337 jupyter
#RUN groupdel jupyter RUN mkdir notebooks WORKDIR notebooks ENV TOKEN '' ENTRYPOINT jupyter lab --ip=0.0.0.0 --allow-root --notebook-dir=/notebooks/ --ServerApp.token=${TOKEN}

2. 构建镜像

docker build -t dotnet-interactive:1.0.0 .

启动容器

执行以下指令启动容器:

docker run --name dotnet-interactive -d -e TOKEN=123456 -v /root/notebooks:/notebooks -p 80:8888 dotnet-interactive:1.0.0

指令解析:

docker run 启动 docker 容器
-- name dotnet-interactive 设置容器名称为 nginx
-d 后台运行
-e TOKEN=123456 设置访问密码为 123456,可根据需要进行调整
-v /root/notebooks:/notebooks 把容器目录挂载到宿主机
-p 80:8888 把宿主机的 80 端口映射到容器的 8888 端口
dotnet-interactive:1.0.0 使用镜像

使用介绍

1. 打开网页并登录

2. 新建 Notebook

3. 解析 Markdown

输入一段 markdown 内容,并选择 Markdown,使用热键 Alt+Enter 查看结果

4. 执行 C# 代码

输入一段 C# 代码,并选择 Code,使用热键 Alt+Enter 查看结果

5. 获取操作系统信息

6. 获取 .Net 版本

7. 获取 ipynb 文件

可以在宿主机的 /root/notebooks 路径下获取刚才操作的 ipynb 文件:

参考总结

以上就是本文希望分享的内容,其中 interactive 的 Github 地址为:https://github.com/dotnet/interactive

如果大家有什么问题,欢迎在文章或者在公众号 - 跬步之巅留言交流。

最新文章

  1. hbase 遇到过的问题
  2. 大家一起和snailren学java-(七)多态
  3. Js高程笔记->引用类型
  4. 网络编程之PC版与Android手机版带断点续传的多线程下载
  5. Javascript数组中shift()和push(),unshift()和pop()操作方法使用
  6. 浅谈sqlldr
  7. 设计模式 --> MVC,MVP 和 MVVM 的图示
  8. maven jdk版本
  9. Ajax增删改查-----------查
  10. MYSQL 如何完全卸载数据库
  11. finally语句块
  12. mysql-unsha1:在未知密码情况下,登录任意MYSQL数据库
  13. unity3D中 material中tiling和offset属性解释
  14. [buaa-SE-2017]个人作业-期末总结
  15. Kernel的IIC驱动分析
  16. 手脱ASPack v2.12
  17. eureka-5- Eureka 的自我保护模式
  18. flask第十七篇——模板【1】
  19. java web 程序--注册页面/HashMap的用法。。要懂啊
  20. POJ - 1061 扩展gcd

热门文章

  1. 学习heartbeat-01简介
  2. 模型预测控制(MPC)简介
  3. 数字电路基础知识——组合逻辑电路(数据选择器MUX、多路复用器)
  4. 13_奈奎斯特稳定性判据_Nyquist Stability Criterion_Part 1
  5. vue和mint-ui loadMore 实现上拉加载和下拉刷新
  6. JavaScript 工作原理之三-内存管理及如何处理 4 类常见的内存泄漏问题(译)
  7. Mybatis实现简单增删改查
  8. 使用ABP SignalR重构消息服务(二)
  9. 挖矿病毒分析(centos7)
  10. MySQL启动过程详解三:Innodb存储引擎的启动