Linux Centos7 install jupyter notebook using Docker container

First enter the container

docker run -it centos:7 /bin/bash

Install jupyter in the container

This process is basically the same as the process of installing jupyter on the centos system, but the centos in the container is the simplest environment and the pip package is not installed.

Ready to work

# 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

Install 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.

If you use pip to upgrade to the latest version, you may get an error when you use pip to install the package: sys.stderr.write(f“ERROR: {exc}“) .

The cause of the problem: refer to  https://blog.csdn.net/xxchaveablog/article/details/114279373

Python 2.7 has expired on January 1, 2020, please stop using it. Please upgrade your Python, because Python 2.7 is no longer maintained. pip 21.0 will stop supporting Python 2.7 in January 2021. pip 21.0 will remove support for this feature.

#使用下面方法安装以前的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 placement

 By default, jupyter can only be accessed through a local address, so you need to let go of the configuration and allow jupyter to remotely access it. When you release remote access, you need to set a password. The configuration file of Jupyter only supports encrypted cipher text passwords.


# 生成 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端口对应

At this time there was another problem: Invalid credentials appeared when logging in to the webpage  , the solution: https://blog.csdn.net/weixin_46248466/article/details/105081120

Various problems appeared during the installation, but they were all resolved in the end.

In order to facilitate future use, commit the container to a mirror image for the next use

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密码

Use ` http://ubuntu-ip:8888` Access after successful startup .

Reference materials: https://blog.csdn.net/leng_yan/article/details/87208363

Guess you like

Origin blog.csdn.net/weixin_42467709/article/details/114535935