《防删除转载》在docker容器内安装jupyterlab

由于最近要做华为昇腾杯2021的变化检测决赛,决赛要求提交docker镜像,并在docker内安装jupyterlab以进行调试,参考了该博主的文章进行了jupyterlab部分的配置。为了防止博主删除,以及便于记忆,故进行了转载。
转载自https://blog.csdn.net/weixin_42730096/article/details/104680842,侵删。

  1. 拉取最新的Ubuntu镜像
docker pull ubuntu
  1. 使用该镜像启动ubuntu1容器(前两个步骤可换成使用自己的镜像创建容器,然后在容器内安装jupyterlab)
docker run -p 8888:8888 -itd --name ubuntu1 ubuntu /bin/bash
  1. 以进入后再退出容器终端不会导致容器的停止的方式进入容器
docker exec -it ubuntu1 /bin/bash
  1. 修改成阿里源
tee /etc/apt/sources.list <<-'EOF'
deb http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse
EOF

  1. 检查可用的更新并更新
apt update -y
apt upgrade -y
  1. 安装一些必须软件(vim、curl、wget、python3、python3-pip)
apt install vim curl wget python3 python3-pip -y
  1. 更换pip国内源
mkdir ~/.pip
tee ~/.pip/pip.conf <<-'EOF'
[global]
trusted-host =  mirrors.aliyun.com
index-url = https://mirrors.aliyun.com/pypi/simple
EOF

  1. 升级pip
pip3 install --upgrade pip
  1. 安装jupyterlab
pip install jupyterlab
  1. 安装nodejs
curl -sL https://deb.nodesource.com/setup_10.x | bash -
apt install nodejs -y
nodejs --version
  1. 生成jupyterlab的配置文件
jupyter lab --generate-config
  1. 生成密码
    在终端输入ipython,在ipython中输入
from notebook.auth import passwd
passwd()

在其提示下输入密码后生成该密码的sha1码(如’sha1:bfacc3698c16:ffe503dxxxxx0e3483fffed5’),
复制该码备用

  1. 修改jupyterlab的配置文件
vim ~/.jupyter/jupyter_notebook_config.py

可修改以下配置等信息

c.NotebookApp.allow_root = True
c.NotebookApp.open_browser = False
c.NotebookApp.password = u'sha1:bfacc3698c16:ffe503dxxxxx0e3483fffed5'# 此为上述密码的sha1码
c.NotebookApp.ip = '*'
c.NotebookApp.port = 8888
  1. exit退出容器后可使用 docker commit 来提交容器副本生成我们的新镜像
docker commit -m="jupyterlab ubuntu" ubuntu1 jupyterlab
  1. 我们可以使用 docker images 命令来查看我们的新镜像

你可能感兴趣的:(docker,容器,jupyterlab)