交互式 .Net 容器版
背景介绍
在之前的文章 - 交互式 .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
如果大家有什么问题,欢迎在文章或者在公众号 - 跬步之巅留言交流。
交互式 .Net 容器版的更多相关文章
- 容器版Jenkins连接Kubernetes---------非容器版jenkins是无法安装kubenetes插件的,所以无法连接k8s
容器版Jenkins连接Kubernetes 特别注意:必须用谷歌浏览器,而且非容器版jenkins是无法安装kubernetes插件的,所以无法连接k8s 一.环境说明 OS系统版本:Ubuntu ...
- 容器版jenkins安装并且实现使用宿主机docker命令,采用的是docker outside deocker,带jdk、添加maven、git
docker版jekins使用宿主机docker命令 docker版jekins安装,实现CI/CD,也就是实现在容器里面使用宿主机docker命令,这样方式为:docker outside deoc ...
- 容器版Jenkins官方镜像 本身自带了 Java
docker版Jenkins官方镜像 本身自带了 Java
- jenkins--master/slave模式---master是容器版---slave是非容器版
实验架构: 192.168.0.96 gitlab 192.168.0.97 jenkins.tomcat 192.168.0.98 harbor.docker集群.git.jdk.maven 1.先 ...
- 容器版单个jenkins实现CI/CD----带solo博客开源项目
实验架构: 192.168.0.96 gitlab 192.168.0.97 jenkins.docker-1.7 192.168.0.98 harbor.docker-1.7集群 jenkins安装 ...
- Docker容器版Jumpserver堡垒机搭建部署方法附Redis
1.简介 Jumpserver是全球首款完全开源的堡垒机,多云环境下更好用的堡垒机,使用GNU GPL v2.0开源协议,是符合 4A 的专业运维安全审计系统,使用Python / Django 进行 ...
- 伤透了心的pytorch的cuda容器版
公司GPU的机器版本本比较低,找了好多不同的镜像都不行, 自己从anaconda开始制作也没有搞定(因为公司机器不可以直接上网), 哎,官网只有使用最新的NVIDIA驱动,安装起来才顺利. 最后,找到 ...
- 容器版jenkins使用宿主机的docker命令
参照里面的第一步里面的dockerfile: https://www.cnblogs.com/effortsing/p/10486960.html
- 容器版jenkins使用宿主机的kubectl命令
参照里面的第4步: https://www.cnblogs.com/effortsing/p/10486960.html
随机推荐
- idea常见设置一
1.顶部执行栏调整 原: 设置:勾选view==>toolbar 后: 这个一看其实没有什么太大的作用,但是你看这个按钮 这个按钮就是File==>Settings,这样会稍微方便点,只要 ...
- hitcon_2017_ssrfme
hitcon_2017_ssrfme 进入环境给出源码 <?php if (isset($_SERVER['HTTP_X_FORWARDED_FOR'])) { $http_x_headers ...
- 解决联想笔记本 安装VM虚拟机后每次启动都会导致电脑蓝屏问题
现象描述: pc为联想笔记本 系统是微软家庭中文版,每次启动VM虚拟机都会出现蓝屏现象,出现错误代码system_service_exception 原因及解决方法: 对于Windows10家庭版 ...
- EMC EMI EMS定义与区别
一.EMC EMI EMS定义: EMC(ElectromagneticCompatibility) 电磁兼容,是指设备或系统在电磁环境中性能不降级的状态.电磁兼容,一方面要求系统内没有严重的干扰源, ...
- 使用Google Closure Compiler高级压缩Javascript代码
背景 前端开发中,特别是移动端,Javascript代码压缩已经成为上线必备条件. 如今主流的Js代码压缩工具主要有: 1)Uglify http://lisperator.net/uglifyjs/ ...
- 使用 jfinal + beetl + bootstrap 实现商城展示及管理系统
使用 jfinal+beetl 在线商品展示系统 使用 git clone https://github.com/zhouchong741/jfinal-demo.git 使用 IntelliJ ID ...
- 关于CSS的个人理解
CSS的个人理解 一.概念 层叠样式表,主要由属性和属性值(value)组成.(虽然HTML.CSS对代码大小写不敏感,但是属性和属性值对代码大小写是敏感的) 二.工作方式 1.工作原理 由浏览器将C ...
- URLDNS反序列化链学习
URLDNS URLDNS跟CommonsCollections比起来真是眉清目秀,该链主要用于验证漏洞,并不能执行命令,优点就是不依赖任何包. 1.利用链 * Gadget Chain: * Has ...
- 函数 装饰器 python
今日内容概要 1.闭包函数 2.闭包函数的实际应用 3.装饰器简介(重点加难点) 4.简易版本装饰器 5.进阶版本装饰器 6.完整版本装饰器 7.装饰器模板(拷贝使用即可) 8.装饰器语法糖 9.装饰 ...
- css 实现随风摆动
无标题文档 @-webkit-keyframes open { 0% { -webkit-transform: rotateX(-120deg); } 25% { -webkit-transform: ...