在码头上运行conda的jupyter

时间:2018-02-17 15:02:58

标签: docker anaconda

我正在使用docker image continuumio / anaconda3,并希望通过浏览器启动带有conda的jupyter笔记本服务器......

docker run -i -t -p 8888:8888 continuumio/anaconda3 /bin/bash -c "/opt/conda/bin/conda install jupyter -y --quiet && mkdir /opt/notebooks && /opt/conda/bin/jupyter notebook --notebook-dir=/opt/notebooks --ip='*' --port=8888 --no-browser"

导致......

Package plan for installation in environment /opt/conda:

The following packages will be UPDATED:

    anaconda: 5.0.1-py36hd30a520_1  --> custom-py36hbbc8b67_0
    conda:    4.3.30-py36h5d9f9f4_0 --> 4.4.10-py36_0        
    jupyter:  1.0.0-py36h9896ce5_0  --> 1.0.0-py36_4         
    pycosat:  0.6.2-py36h1a0ea17_1  --> 0.6.3-py36h0a5515d_0 

[I 14:59:00.461 NotebookApp] Writing notebook server cookie secret to /root/.local/share/jupyter/runtime/notebook_cookie_secret
[W 14:59:00.475 NotebookApp] WARNING: The notebook server is listening on all IP addresses and not using encryption. This is not recommended.
[I 14:59:00.498 NotebookApp] JupyterLab alpha preview extension loaded from /opt/conda/lib/python3.6/site-packages/jupyterlab
JupyterLab v0.27.0
Known labextensions:
[I 14:59:00.499 NotebookApp] Running the core application with no additional extensions or settings
[C 14:59:00.502 NotebookApp] Running as root is not recommended. Use --allow-root to bypass.

如果我使用

$ docker run -p 8888:8888 -i -t continuumio/anaconda3 /bin/bash
root@083f8fbb5d3b:/# jupyter notebook

它给了......

[I 15:00:52.496 NotebookApp] Writing notebook server cookie secret to /root/.local/share/jupyter/runtime/notebook_cookie_secret
Traceback (most recent call last):
  File "/opt/conda/bin/jupyter-notebook", line 11, in <module>
    sys.exit(main())
  File "/opt/conda/lib/python3.6/site-packages/jupyter_core/application.py", line 267, in launch_instance
    return super(JupyterApp, cls).launch_instance(argv=argv, **kwargs)
  File "/opt/conda/lib/python3.6/site-packages/traitlets/config/application.py", line 657, in launch_instance
    app.initialize(argv)
  File "<decorator-gen-7>", line 2, in initialize
  File "/opt/conda/lib/python3.6/site-packages/traitlets/config/application.py", line 87, in catch_config_error
    return method(app, *args, **kwargs)
  File "/opt/conda/lib/python3.6/site-packages/notebook/notebookapp.py", line 1296, in initialize
    self.init_webapp()
  File "/opt/conda/lib/python3.6/site-packages/notebook/notebookapp.py", line 1120, in init_webapp
    self.http_server.listen(port, self.ip)
  File "/opt/conda/lib/python3.6/site-packages/tornado/tcpserver.py", line 142, in listen
    sockets = bind_sockets(port, address=address)
  File "/opt/conda/lib/python3.6/site-packages/tornado/netutil.py", line 197, in bind_sockets
    sock.bind(sockaddr)
OSError: [Errno 99] Cannot assign requested address

我应该如何运行Jupyter笔记本?

5 个答案:

答案 0 :(得分:4)

谢谢darthbirth先生,

*.pmc

并且你已经启动并运行了Jupyter笔记本电脑。

按ctrl并点击终端上的“使用令牌登录”链接

$ docker run -p 8888:8888 -i -t continuumio/anaconda3 /bin/bash

jupyter notebook --ip=0.0.0.0 --port=8888 --allow-root

答案 1 :(得分:0)

要运行Jupyter Notebook而无需进入Docker容器,请执行以下操作:

  1. 获取docker映像

    docker pull continuumio/anaconda3

  2. 安装并启动Jupyter Notebook

    docker run -i -t -p 8888:8888 continuumio/anaconda3 /bin/bash -c "/opt/conda/bin/conda install jupyter -y --quiet && mkdir /opt/notebooks && /opt/conda/bin/jupyter notebook --notebook-dir=/opt/notebooks --ip='*' --port=8888 --no-browser --allow-root"

    请注意,我们正在传递--allow-root标志。

  3. 安装后,笔记本服务器应显示带有令牌的链接:

Jupyter Notebook running in Docker

  1. 在浏览器上,访问提供的网址之一或使用localhost

http://localhost:8888/?token=YOUR_TOKEN

答案 2 :(得分:0)

使用该线程中的答案,我提供了一个衬板来运行带有最新的Anaconda docker映像(4.0)的Jupyter笔记本,它将与容器共享您的当前目录,从而将笔记本保存在主机上。

docker run -t --rm -p 8888:8888 -v $(PWD):/opt/notebooks continuumio/anaconda /bin/bash -c "/opt/conda/bin/jupyter notebook --ip=0.0.0.0 --port=8888 --notebook-dir=/opt/notebooks --allow-root --no-browser"

请注意,通过将当前工作目录映射为容器(-v $(PWD):/opt/notebooks)中的卷,然后将其指定为Jupyter的笔记本目录(--notebook-dir=/opt/notebooks),则无需创建目录。 Docker将自动为您执行此操作,并将其与您的主机共享。还要注意,通过在调用中添加--rm,一旦您关闭Jupyter服务器,泊坞窗就会删除容器,这样您以后就不必清理它们了。

您也可以像这样在.bash_profile中将其用作别名:

alias jupyter='docker run -t --rm -p 8888:8888 -v $(PWD):/opt/notebooks continuumio/anaconda /bin/bash -c "/opt/conda/bin/jupyter notebook --ip=0.0.0.0 --port=8888 --notebook-dir=/opt/notebooks --allow-root --no-browser"'

然后您可以使用:

$ jupyter

任何时候您想使用jupyter notebook并将当前目录用作笔记本文件夹。 (希望这对某人有帮助)

答案 3 :(得分:0)

我正在运行此的docker上使用anaconda

  

docker run -it --rm --name ds -p 8888:8888 jupyter / datascience-notebook

使用它并告诉我

答案 4 :(得分:0)

参加聚会可能会有点晚,但是经过几天的反复试验,我整理了dockerdocker-compose的文件。我正在发布我的docker-composedockerenvironment.yaml文件。希望它能在一段时间前帮助像我这样的可怜人:

docker个文件:

FROM continuumio/miniconda3

# Update conda.
RUN conda update -n base -c defaults conda

# Create the environment:
COPY environment.yml .
RUN conda env create -f environment.yml

WORKDIR /home

ENTRYPOINT ["conda", "run", "-n", "myenv", "jupyter", "notebook", "--ip=0.0.0.0", "--port=8080", "--allow-root", "--NotebookApp.token=''", "--NotebookApp.password=''"]

docker-compose文件:

version: '3'

services:
  miniconda:
    container_name: 'jupyter_docker'
    build: '.'
    ports:
      - 8080:8080
    volumes:
      - $PWD/files:/home

environment.yaml文件:

name: myenv
channels:
  - conda-forge
  - defaults
dependencies:
  - jupyter
  - python=3.8.2=hcf32534_0
  - pip:
    - datetime

使用docker-compose运行非常简单,如果单个命令docker-compose up不存在,则会创建一个图像并设置一个容器。从那里,只需转到localhost:8080上的浏览器。完成后,运行docker-compose down --rmi all --remove-orphans删除容器和图像。