背景介绍

在之前的文章 - 交互式 .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 容器版的更多相关文章

  1. 容器版Jenkins连接Kubernetes---------非容器版jenkins是无法安装kubenetes插件的,所以无法连接k8s

    容器版Jenkins连接Kubernetes 特别注意:必须用谷歌浏览器,而且非容器版jenkins是无法安装kubernetes插件的,所以无法连接k8s 一.环境说明 OS系统版本:Ubuntu ...

  2. 容器版jenkins安装并且实现使用宿主机docker命令,采用的是docker outside deocker,带jdk、添加maven、git

    docker版jekins使用宿主机docker命令 docker版jekins安装,实现CI/CD,也就是实现在容器里面使用宿主机docker命令,这样方式为:docker outside deoc ...

  3. 容器版Jenkins官方镜像 本身自带了 Java

    docker版Jenkins官方镜像 本身自带了 Java

  4. 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.先 ...

  5. 容器版单个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安装 ...

  6. Docker容器版Jumpserver堡垒机搭建部署方法附Redis

    1.简介 Jumpserver是全球首款完全开源的堡垒机,多云环境下更好用的堡垒机,使用GNU GPL v2.0开源协议,是符合 4A 的专业运维安全审计系统,使用Python / Django 进行 ...

  7. 伤透了心的pytorch的cuda容器版

    公司GPU的机器版本本比较低,找了好多不同的镜像都不行, 自己从anaconda开始制作也没有搞定(因为公司机器不可以直接上网), 哎,官网只有使用最新的NVIDIA驱动,安装起来才顺利. 最后,找到 ...

  8. 容器版jenkins使用宿主机的docker命令

    参照里面的第一步里面的dockerfile: https://www.cnblogs.com/effortsing/p/10486960.html

  9. 容器版jenkins使用宿主机的kubectl命令

    参照里面的第4步: https://www.cnblogs.com/effortsing/p/10486960.html

随机推荐

  1. C++ | 虚函数表内存布局

    虚表指针 虚函数有个特点.存在虚函数的类会在类的数据成员中生成一个虚函数指针 vfptr,而vfptr 指向了一张表(简称,虚表).正是由于虚函数的这个特性,C++的多态才有了发生的可能. 其中虚函数 ...

  2. ES6-11学习笔记--对象的扩展

    属性简洁表示法 属性名表达式 Objec.is() 扩展运算符 与 Object.assign() in 对象的遍历方式   属性简洁表示法: 如果属性key跟变量名一样,可简写 let name = ...

  3. java中接口到底是干什么的,怎么用,深入剖析

    6.总结性深一层次综合剖析接口概念[新手可忽略不影响继续学习] 通过以上的学习, 我们知道,所有定义在接口中的常量都默认为public.static和final.所有定义在接口中的方法默认为publi ...

  4. Override,Overload,Overwrite到底有什么区别?

    Override,Overload,Overwrite的区别[新手可忽略不影响继续学习] 方法的覆盖(Override)是指子类重写从父类继承来的一个同名方法(参数.返回值也同),马克-to-win: ...

  5. java中请给出例子程序:找出n到m之间的质数。

    9.1 找出100到200之间的质数.  public class Test {     public static void main(String[] args){         for (in ...

  6. javascript,如何实现数据绑定

    在三大框架 抢占前端开发技术领域的时代,基本每个框架都是实现了数据绑定, 今天我们来解密一下数据绑定的原理, 原理关乎一个很关键的东西,Object.prototype.__defineSetter和 ...

  7. 玩转NET Expression

    using System; using System.Collections.Generic; using System.ComponentModel.DataAnnotations.Schema; ...

  8. 使用Socket实现HttpServer(一)

    使用Socket实现HttpServer(一) Socket 编程 socket 翻译过来叫插槽,一张图你就明白 socket 就插在 TCP 也就是传输层上,对用户的请求和服务器的响应进行处理. 下 ...

  9. kubectl scale 一次缩容调整过程

    查看master环境相关信息一.版本信息 [root@master-web-38 ~]# kubectl versionClient Version: version.Info{Major:" ...

  10. i.MX rt 系列微控制器的学习记录

    杂记 前言 我总是很希望自己能产生一种感知电压变化的能力,就像B站上的教学动图中,电流从电源流出时导线就像LED亮起来一样,我将指尖触到导线上就能感受到实时的电压变化.我在上学和工作时经常由于无法理解 ...