最初にコンテナに入る
docker run -it centos:7 /bin/bash
コンテナにjupyterをインストールします
このプロセスは基本的にcentosシステムにjupyterをインストールするプロセスと同じですが、コンテナー内のcentosは最も単純な環境であり、pipパッケージはインストールされません。
準備オーケー
# 1、更新yum
yum update -y
#2、安装 epel 源。如果不安装epel 源,后面安装pip的时候可能会报错:
# No package python-pip available.
# Error: Nothing to do
yum install epel-release -y
#3、centos镜像自带python2.7,但是没有安装 pip ,还需要安装pip
yum install python-pip
jupyterをインストールします
pip install jupyter
# 我这里出现了以下报错(2021年3月8日):
Complete output from command python setup.py egg_info:
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/tmp/pip-build-Upoocz/nbconvert/setup.py", line 81
print("Failed, try again after installing PycURL with `pip install pycurl`
to avoid outdated SSL.", file=sys.stderr)
^
SyntaxError: invalid syntax
----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-build-Upoocz/nbconvert/
You are using pip version 8.1.2, however version 21.0.1 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.
pipを使用して最新バージョンにアップグレードする場合、pipを使用してパッケージをインストールするとエラーが発生する可能性があります:sys.stderr.write(f "ERROR:{exc}")。
問題の原因:https://blog.csdn.net/xxchaveablog/article/details/114279373を参照して ください
Python2.7は2020年1月1日に期限切れになりました。使用を中止してください。Python 2.7はメンテナンスされていないため、Pythonをアップグレードしてください。pip 21.0は、2021年1月にPython2.7のサポートを停止します。pip 21.0は、この機能のサポートを削除します。
#使用下面方法安装以前的pip版本解决:
# yum remove python-pip
yum install -y wget
wget https://bootstrap.pypa.io/pip/2.7/get-pip.py
python get-pip.py
# 然后就可以安装jupyter了
# 再次运行 pip install jupyter
jupyter配置
デフォルトでは、jupyterはローカルアドレスを介してのみアクセスできるため、構成を手放し、jupyterがリモートでアクセスできるようにする必要があります。リモートアクセスを解除するときは、パスワードを設定する必要があります。Jupyterの設定ファイルは、暗号化された暗号文パスワードのみをサポートしています。
# 生成 jupyter 配置文件,这个会生成配置文件 .jupyter/jupyter_notebook_config.py
jupyter notebook --generate-config
# 运行ipython 命令生成密码
In [1]: from notebook.auth import passwd
In [2]: passwd()
Enter password:
Verify password:
Out[2]: 'sha1:******'
# 记得把 sha1 后面的密码保存起来,后面要用到
#去配置文件.jupyter/jupyter_notebook_config.py中修改以下参数
c.NotebookApp.allow_remote_access=True
c.NotebookApp.ip='*' #绑定所有地址
c.NotebookApp.open_browser = False #启动后是否在浏览器中自动打开
c.NotebookApp.password = u'刚才生成的密码'
c.NotebookApp.port =8888 #指定一个访问端口,默认8888,注意和映射的docker端口对应
このとき、別の問題がありました。Webページにログインすると、無効な資格情報が表示されまし た。解決策:https://blog.csdn.net/weixin_46248466/article/details/105081120
インストール中にさまざまな問題が発生しましたが、最終的にはすべて解決しました。
将来の使用を容易にするために、次の使用のためにコンテナをミラーイメージにコミットします
docker commit 容器id jupyter-centos:1.0
# 最终命令
docker run -it -p 8888:8888 jupyter-centos:1.0 su root -c 'jupyter notebook --allow-root --NotebookApp.password=sha1:xxxx /mnt'
# xxxx是你的sha1密码
正常に起動しhttp://ubuntu-ip:8888`
た後、 ` Accessを使用します。
参考資料:https://blog.csdn.net/leng_yan/article/details/87208363