背景介绍

在之前的文章 - 交互式 .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. freemarker与vue使用图片路径获取问题,可双单引号一起使用则可

    <el-table :data="leftPage.datas" style="width: 100%"  @selection-change=" ...

  2. Numpy对数组按索引查询

    Numpy对数组按索引查询 三种索引方法: 基础索引 神奇索引 布尔索引 基础索引 一维数组 和Python的List一样 二维数组 注意:切片的修改会修改原来的数组 原因:Numpy经常要处理大数组 ...

  3. 你不需要基于 CSS Grid 的栅格布局系统

    在过去的几个星期里,我开始看到基于 CSS Grid 的布局框架和栅格系统的出现.我们惊讶它为什么出现的这么晚.但除了使用 CSS Grid 栅格化布局,我至今还没有看到任何框架能提供其他有价值的东西 ...

  4. javaweb之删除功能

    对数据库的删除,主要是通过表中的一个数据查询来进行逐个删除,否则会清空整张表. 一.dao层 在dao层加入删除方法 public boolean delete(Course n) { boolean ...

  5. 手机上无法显示Toast信息

    关于手机上无法显示Toast信息, 是因为手机上的权限没有开, 在应用管理处将所有权限都打开,就可以显示了.

  6. 控制器全屏显示.不展示导航栏navigationbar

    有些时候需要 让控制器全屏显示 ,不需要导航栏,或者说是在导航栏底部 基本情况: >控制器全屏 ``` if (@available(iOS 11.0, *)) { self.tableView ...

  7. Linux---必备命令(2)

    进程相关命令 # 查看系统所有的进程 ps -ef ps -ef | grep vim # 过滤出vim有关的进程 ps -ef | grep vim # 过滤出22端口的信息 ps -tunlp | ...

  8. spring原始注解

    spring原始注解主要是替代Bean标签的配置 @Component:使用在类上用于实例化Bean @Controller:使用在web层类上用于实例化Bean @Service:使用在servic ...

  9. oracle之lsnrctl命令

    采样: [oracle@sh02 ~]$ cat /etc/redhat-release Red Hat Enterprise Linux Server release 6.4 (Santiago) ...

  10. 用 getElementsByTagName() 来获取,父元素指定的子元素

    1. html 结构 <ul> <li>知否知否,应是等你好久11</li> <li>知否知否,应是等你好久11</li> <li&g ...