Shankze
Shankze

Reputation: 4099

Docker - unable to run Jupyter notebook - KeyError: 'allow_remote_access'

This is my first time using Docker. I am trying to install jupyter and run an ipynb file. I tried 2 images and ran into the same error on both:
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"]

Build:

docker build -t helloworld_container .

Run:

docker run -p 9999:8888 helloworld_container 

I get the following error:

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

I think a potential fix to this issue is to update the jupyter_notebook_config.py file. So I need to generate the file using:

jupyter notebook --generate-config

I need to uncomment

#c.NotebookApp.ip = ‘*’

and set it to:

c.NotebookApp.ip = ‘0.0.0.0’

I know how to perform these steps on my machine but I do not know how to perform these steps on the image. So I generated the config file on my machine, made the changes and then copied it to the container by adding the following line to the dockerfile(and creating a new container):

COPY jupyter_notebook_config.py /config/location/jupyter_notebook_config.py

This did not fix the issue.

For now, I have moved to a different image (tensorflow\tensorflow) that has jupyter installed but I want to know what am I doing wrong.

Upvotes: 1

Views: 2117

Answers (3)

lmiguelvargasf
lmiguelvargasf

Reputation: 69705

I wanted to run Jupyter notebooks using Docker, and I faced the same problem you have reported. Fortunately, I was able to find a solution.

Note: I am using the continuumio/anaconda3 image.

Steps

  1. Pull the image from Docker Hub
docker pull continuumio/anaconda3
  1. Run the following command (the one provided the documentation image doesn't work and generates the error you have reported)
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='0.0.0.0' --port=8888 --no-browser --allow-root"

There are two crucial modifications to make this work. First, use --ip='0.0.0.0' instead of --ip='*'. Second, add --allow-root to see the notebooks running in the browser.

Adding a volume in a temporal container

If you want to create a temporal container, i.e., one that is removed once it stops running, and you want to create a volume so that you can keep, in your host, the files you created inside the container, use the following command:

docker run --volume /path/in/your/host/jupyter_notebooks:/opt/notebooks --rm -it -p 8888:8888 continuumio/anaconda3 /bin/bash -c "/opt/conda/bin/conda install jupyter -y --quiet && /opt/conda/bin/jupyter notebook --notebook-dir=/opt/notebooks --ip='0.0.0.0' --port=8888 --no-browser --allow-root"

Upvotes: 0

de1
de1

Reputation: 3124

You already identified the problem yourself in that you noticed that you had to replace * with 0.0.0.0. But instead of doing that in the configuration you can simply do that in your command (no need to use bash):

CMD ["jupyter", "notebook", "--ip=0.0.0.0", "--port=8888", "--no-browser", "--allow-root"]

This is an issue that was introduced through a bug in notebook and also reported in docker-stacks.

Upvotes: 0

Danielle M.
Danielle M.

Reputation: 3662

At a guess, this line, specifically, the "--ip='*'" is the problem:

CMD ["jupyter","notebook","--ip='*'","--port=8888","--no-browser","--allow-root"]

I'm not sure how docker files handle escaping, but the error states that the ip address is somehow wrong:

ValueError: '' does not appear to be an IPv4 or IPv6 address

Try this instead, much less escaping issues:

CMD["/bin/bash", "-lc", "jupyter notebook --ip=0.0.0.0 --port=8888 --no-browser --allow-root"]

Upvotes: 1

Related Questions