简体   繁体   English

在 docker 上运行 conda 的 jupyter

[英]running conda's jupyter on docker

I am using the docker image continuumio/anaconda3 and want to start jupyter notebook server with conda via browser ...我正在使用 docker image continuumio/anaconda3 并想通过浏览器使用 conda 启动 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"

which results in ...这导致...

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.

and if I use如果我使用

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

it gives ...它给...

[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

How should I run Jupyter notebook?我应该如何运行 Jupyter 笔记本?

Thanks Mr. darthbirth,谢谢达斯伯恩先生,

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

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

and the you have Jupyter notebook up and running.并且您已经启动并运行了 Jupyter 笔记本。

Press ctrl and click the "login with a token" link on your terminal that looks like,按 ctrl 并单击终端上的“使用令牌登录”链接,如下所示,

http://0.0.0.0:8888/?token= ...

or

http://127.0.0.1:8888/?token= ...

Using the answers in this thread, I have come up with a one liner for running Jupyter notebooks with the latest Anaconda docker image (4.0) that will share your current directory with the container and thus saving the notebooks on your host computer.使用此线程中的答案,我想出了一个单行代码,用于运行带有最新 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"

Note that by mapping your current working directory as a volume in the container ( -v $(PWD):/opt/notebooks ) and then specifying that as the notebook directory to Jupyter ( --notebook-dir=/opt/notebooks ) you don't need to make the directory.请注意,通过将当前工作目录映射为容器中的卷( -v $(PWD):/opt/notebooks ),然后将其指定为 Jupyter 的笔记本目录( --notebook-dir=/opt/notebooks ),您不需要制作目录。 Docker will automatically do that for you and share it with your host computer. Docker 会自动为您执行此操作并与您的主机共享。 Also note that by adding --rm to the call, docker will remove the container once you shut down the Jupyter server so that you don't have to clean them up later.另请注意,通过将--rm添加到调用中,一旦您关闭 Jupyter 服务器,docker 将删除容器,以便您以后不必清理它们。

You can also use it as an alias in your .bash_profile like this:您还可以将其用作.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"'

Then you can just use:然后你可以使用:

$ jupyter

any time you want to use jupyter notebook using the current directory as your notebook folder.任何时候你想使用jupyter notebook使用当前目录作为你的 notebook 文件夹。 (hope this is helpful to someone) (希望这对某人有帮助)

To run Jupyter Notebook without going into the Docker container do:要在不进入 Docker 容器的情况下运行 Jupyter Notebook,请执行以下操作:

  1. Get the docker image获取 docker 镜像

    docker pull continuumio/anaconda3

  2. Install and start Jupyter Notebook安装并启动 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"

    Note that we are passing the --allow-root flag.请注意,我们正在传递--allow-root标志。

  3. After installing, the Notebook server should show a link with a token:安装后,笔记本服务器应该显示一个带有令牌的链接:

在 Docker 中运行的 Jupyter Notebook

  1. On your browser visit one of the provided URLs or use localhost :在您的浏览器上访问提供的 URL 之一或使用localhost

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

I might be a bit late for the party, but after couple days of trial and error I have put together docker and docker-compose files that I am using.我参加聚会可能有点晚了,但是经过几天的反复试验,我已经将我正在使用的dockerdocker-compose文件放在一起。 I am posting my docker-compose , docker and environment.yaml files.我正在发布我的docker-composedockerenvironment.yaml文件。 Hope it helps those poor souls like myself some time ago:希望前段时间能帮到像我这样的可怜人:

docker file: 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 file: docker-compose文件:

version: '3'

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

And environment.yaml file:environment.yaml文件:

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

Running with docker-compose is super simple, a single command docker-compose up creates image if it does not exist already and sets up a container.使用 docker-compose 运行非常简单,单个命令docker-compose up会创建镜像(如果镜像尚不存在)并设置一个容器。 From there, just go to your browser at localhost:8080 .从那里,只需转到您的浏览器localhost:8080 Run docker-compose down --rmi all --remove-orphans to remove container and image after you are done.完成后运行docker-compose down --rmi all --remove-orphans以删除容器和图像。

I'm using anaconda on docker running this我在运行这个的 docker 上使用 anaconda

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

Use it and tell me使用它并告诉我

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM