如何使用python 2.x安装jupyter / docker-stacks

时间:2018-02-02 21:08:53

标签: python-2.7 docker containers jupyter-notebook jupyter

我想使用docker-stacks安装python 2.X中的一个jupyter容器。

GitHub上有关jupyter / docker-stacks的文档说:

  

Python 2.x于2017年8月10日从所有图片中删除,从标签cc9feab481f7开始。如果您希望继续使用Python 2.x,请将其标记为82b978b3ceeb。

请参阅: https://github.com/jupyter/docker-stacks

我假设您按照以下方式运行,例如,安装minimal-notebook:

docker run -it --rm -p 8888:8888 jupyter/minimal-notebook:82b978b3ceeb

但是在运行后我发现安装了python 3.x:

sys.version_info(major = 3,minor = 6,micro = 2,releaselevel =' final',serial = 0)

这是' docker run'的输出。命令:

$ docker run -it --rm -p 8888:8888 jupyter/minimal-notebook:82b978b3ceeb
/usr/local/bin/start.sh: line 48: [: missing `]'
/usr/local/bin/start.sh: line 48: : command not found
Execute the command
[I 20:55:49.950 NotebookApp] Writing notebook server cookie secret to /home/jovyan/.local/share/jupyter/runtime/notebook_cookie_secret
[W 20:55:49.979 NotebookApp] WARNING: The notebook server is listening on all IP addresses and not using encryption. This is not recommended.
[I 20:55:50.010 NotebookApp] JupyterLab alpha preview extension loaded from /opt/conda/lib/python3.6/site-packages/jupyterlab
JupyterLab v0.24.1
Known labextensions:
[I 20:55:50.013 NotebookApp] Running the core application with no additional extensions or settings
[I 20:55:50.016 NotebookApp] Serving notebooks from local directory: /home/jovyan
[I 20:55:50.016 NotebookApp] 0 active kernels 
[I 20:55:50.017 NotebookApp] The Jupyter Notebook is running at: http://[all ip addresses on your system]:8888/?token=f09a12bf53902cb20aca2f1924011e1e80d51243cc10a390
[I 20:55:50.017 NotebookApp] Use Control-C to stop this server and shut down all kernels (twice to skip confirmation).
[C 20:55:50.017 NotebookApp] 

    Copy/paste this URL into your browser when you connect for the first time,
    to login with a token:
        http://localhost:8888/?token=f09a12bf53902cb20aca2f1924011e1e80d51243cc10a390

2 个答案:

答案 0 :(得分:1)

有一个在FROM GitHub维基上的核心图像之一中创建Python 2 conda环境的方法:https://github.com/jupyter/docker-stacks/wiki/Docker-recipes#add-a-python-2x-environment

答案 1 :(得分:1)

我注意到link中建议的previous post不再存在,因此我将其中一些内容进行了一些修改。

您可以创建以下Dockerfile:

# From https://github.com/jupyter/docker-stacks/wiki/Docker-recipes#add-a-python-2x-environment

# Choose your desired base image: you could use another from https://github.com/busbud/jupyter-docker-stacks
FROM jupyter/all-spark-notebook:latest

# Create a Python 2.x environment using conda including at least the ipython kernel
# and the kernda utility. Add any additional packages you want available for use
# in a Python 2 notebook to the first line here (e.g., pandas, matplotlib, etc.)
RUN conda create --quiet --yes -p $CONDA_DIR/envs/python2 python=2.7 ipython ipykernel kernda && \
    conda clean -tipsy

USER root


# Bundle requirements
# You can change the libraries in the file
# requirements.txt
ADD requirements.txt /requirements.txt



# Create a global kernelspec in the image and modify it so that it properly activates
# the python2 conda environment.
RUN $CONDA_DIR/envs/python2/bin/python -m ipykernel install && \
    $CONDA_DIR/envs/python2/bin/kernda -o -y /usr/local/share/jupyter/kernels/python2/kernel.json && \
    pip install -r /requirements.txt && \
    rm /requirements.txt && \

USER $NB_USER

或者如果您没有要求

# From https://github.com/jupyter/docker-stacks/wiki/Docker-recipes#add-a-python-2x-environment

# Choose your desired base image: you could use another from https://github.com/busbud/jupyter-docker-stacks
FROM jupyter/all-spark-notebook:latest

# Create a Python 2.x environment using conda including at least the ipython kernel
# and the kernda utility. Add any additional packages you want available for use
# in a Python 2 notebook to the first line here (e.g., pandas, matplotlib, etc.)
RUN conda create --quiet --yes -p $CONDA_DIR/envs/python2 python=2.7 ipython ipykernel kernda && \
    conda clean -tipsy

USER root



# Create a global kernelspec in the image and modify it so that it properly activates
# the python2 conda environment.
RUN $CONDA_DIR/envs/python2/bin/python -m ipykernel install && \
    $CONDA_DIR/envs/python2/bin/kernda -o -y /usr/local/share/jupyter/kernels/python2/kernel.json &

USER $NB_USER

然后转到文件夹: 创建图像: docker build -t wm/ubuntupython2jupyterpyspark:v1.0 . wm / ubuntupython2jupyterpyspark:v1.0只是一个示例,您可以放另一个

运行容器

docker run -p 8888:8888 wm/ubuntupython2jupyterpyspark:v1.0