本地docker搭建jupyter运行环境

1、容器操作

1、拉取镜像

docker pull ubuntu

2、创建容器

创建容器时要先考虑好自己要开设几个端口,要提前指定好映射关系!!!

docker run -dit --name LocalDocker -p 3303:8888 -p 3301:22 -p 3302:3306 2dc3

  • 2dc3是镜像的ID,使用时要更换

3、进入容器

sed -i ‘s/archive.ubuntu.com/mirrors.aliyun.com/g’ /etc/apt/sources.list
apt-get update
apt-get upgrade

2、安装ssh

1、安装ssh-client和ssh-server

  • 安装client和server

apt-get install openssh-client
apt-get install openssh-server

  • 安装完成后,先启动服务

/etc/init.d/ssh start

2、编辑sshd_config文件

vim /etc/ssh/sshd_config

  • 没有vim的话,先安装

    apt-get install vim

  • 进去之后添加三句话

PubkeyAuthentication yes #启用公钥私钥配对认证方式
PermitRootLogin yes #root能使用ssh登录
Port 22 #指定好端口号,默认是22 后面这个数字要在你run容器的时候用到

UsePAM yes 更改为 UsePAM no

  • 退出vim

:wq

3、重启ssh

service ssh restart

4、设置ssh密码

passwd root

5、本地ssh连接容器

ssh root@127.0.0.1 -p3301

  • 3301是一开始创建容器的时候指定的映射端口

6、安装g++,gdb

apt-get install g++
apt-get install gdb

3、安装Anaconda

1、下载Anaconda包

1、先进入到root目录

cd root

2、下载

wget https://mirrors.tuna.tsinghua.edu.cn/anaconda/archive/Anaconda3-2021.11-Linux-x86_64.sh

2、安装

sh ./Anaconda3-2021.11-Linux-x86_64.sh

按照提示进行安装即可

输入yes进入base环境

再输入以下两条命令

source /root/anaconda3/bin/activate #注意选择自己的路径
conda init

3、添加清华源

conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/
conda config --set show_channel_urls yes

4、安装jupyter lab

conda install jupyterlab

5、设置jupyter lab在后台运行

jupyter lab --allow-root > jupyter.log 2>&1 &

6、更改jupyter lab的工作目录

vim /root/.jupyter/jupyter_lab_config.py

先进入ipython交互式环境生成秘钥

ipython

from notebook.auth import passwd

passwd()

把下面的内容复制到文件中去

c.NotebookApp.port = 8888
#指定jupyter lab 运行端口,要和前面创建容器时指定的端口一样 

c.NotebookApp.allow_remote_access = True
# 允许远程访问 
c.NotebookApp.password = u'上面生成的秘钥'
c.NotebookApp.ip='*'  
# 就是设置所有ip皆可访问  

c.NotebookApp.open_browser = False
# 禁止自动打开浏览器
c.NotebookApp.notebook_dir='/root/Projects'

4、安装MySQL

apt-get install mysql-server -y

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值