【发布时间】:2023-03-10 15:10:01
【问题描述】:
这是我第一次使用 Docker。我正在尝试安装 jupyter 并运行 ipynb 文件。
我尝试了 2 张图片并在两者上都遇到了相同的错误:
1) python:3.6.2-slim
2) jupyter/datascience-notebook
Dockerfile:
#Use this python image
FROM python:3.6.2-slim
#Set metadata
LABEL maintainer="MyName"
#Set working directory to /app
WORKDIR /app
#Copy all files in current directory to working directory (/app)
COPY . /app
#Install the required libraries
RUN pip --no-cache-dir install numpy pandas seaborn sklearn jupyter
#Make port 8888 available to the world outside this Container
EXPOSE 8888
#Run jupyter when container launches
CMD ["jupyter","notebook","--ip='*'","--port=8888","--no-browser","--allow-root"]
构建:
docker build -t helloworld_container .
运行:
docker run -p 9999:8888 helloworld_container
我收到以下错误:
Traceback (most recent call last):
File "/opt/conda/lib/python3.6/site-packages/traitlets/traitlets.py", line 528, in get
value = obj._trait_values[self.name]
KeyError: 'allow_remote_access'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/opt/conda/lib/python3.6/site-packages/notebook/notebookapp.py", line 869, in _default_allow_remote
addr = ipaddress.ip_address(self.ip)
File "/opt/conda/lib/python3.6/ipaddress.py", line 54, in ip_address
address)
ValueError: '' does not appear to be an IPv4 or IPv6 address
During handling of the above exception, another exception occurred:
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 266, 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 1629, in initialize
self.init_webapp()
File "/opt/conda/lib/python3.6/site-packages/notebook/notebookapp.py", line 1379, in init_webapp
self.jinja_environment_options,
File "/opt/conda/lib/python3.6/site-packages/notebook/notebookapp.py", line 158, in __init__
default_url, settings_overrides, jinja_env_options)
File "/opt/conda/lib/python3.6/site-packages/notebook/notebookapp.py", line 251, in init_settings
allow_remote_access=jupyter_app.allow_remote_access,
File "/opt/conda/lib/python3.6/site-packages/traitlets/traitlets.py", line 556, in __get__
return self.get(obj, cls)
File "/opt/conda/lib/python3.6/site-packages/traitlets/traitlets.py", line 535, in get
value = self._validate(obj, dynamic_default())
File "/opt/conda/lib/python3.6/site-packages/notebook/notebookapp.py", line 872, in _default_allow_remote
for info in socket.getaddrinfo(self.ip, self.port, 0, socket.SOCK_STREAM):
File "/opt/conda/lib/python3.6/socket.py", line 745, in getaddrinfo
for res in _socket.getaddrinfo(host, port, family, type, proto, flags):
socket.gaierror: [Errno -2] Name or service not known
我认为此问题的潜在解决方法是更新 jupyter_notebook_config.py 文件。所以我需要使用以下方法生成文件:
jupyter notebook --generate-config
我需要取消注释
#c.NotebookApp.ip = ‘*’
并将其设置为:
c.NotebookApp.ip = ‘0.0.0.0’
我知道如何在我的机器上执行这些步骤,但我不知道如何在图像上执行这些步骤。所以我在我的机器上生成了配置文件,进行了更改,然后通过将以下行添加到 dockerfile(并创建一个新容器)将其复制到容器中:
COPY jupyter_notebook_config.py /config/location/jupyter_notebook_config.py
这并没有解决问题。
目前,我已移至安装了 jupyter 的其他映像 (tensorflow\tensorflow),但我想知道我做错了什么。
【问题讨论】:
-
我已经为您的问题添加了答案。
标签: python docker jupyter-notebook