I have collected some data recently and want to analyze it. Then think of a long time ago to build a Jupyter Lab environment for themselves, choose the day is not as good as the day, simply do today.

So what is a Jupyter Notebook?

Juptyer Notebook is an online interactive computing environment that evolved from IPython and can write documentation that can contain code, text (Markdown), math, ICONS, and rich media. Jupyter Lab is the next generation user interface for Jupyter Notebook.

Simple to fit

Pure run a Jupyter is actually very simple:

pip install jupyterlab
jupyter lab
Copy the code

The above command can run a Jupyter, but requires a Python environment.

Because I want to run on the server, do not want the server environment is too messy, so migration will be very troublesome, so it is best to run in Docker.

Unfortunately, I stepped in so many holes in the Docker deployment process that MY head was completely blown. And this part of the Internet information is less, only official documents and part of the blog involved. So I’m here to record my journey, hoping to help future generations.

So what are my problems?

  1. Docker cannot be started after mounting, prompting permission denied
  2. Error 500 is reported when setting the password after startup
  3. The password does not take effect after startup
  4. 404 error when creating a file

I ran into some of these problems, and each one was pretty weird. Next, please watch my sad journey:

The Jupyter container could not start after Docker mounted the anonymous coupon

You don’t get an error if you just run to the container, but then your data dies with the container, and that’s not acceptable.

Therefore, Jupyter’s data path needs to be mapped to the host. Next, there is a problem with the boot error:

Container must be run with group "users" to update files
Executing the command: jupyter lab
Traceback (most recent call last):
  File "/ opt/conda/lib/python3.7 / site - packages/traitlets/traitlets py." ", line 528, in get
    value = obj._trait_values[self.name]
KeyError: 'runtime_dir'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
"""Stack information is hidden."""
PermissionError: [Errno 13] Permission denied: '/home/jovyan/.local'
Copy the code

At first, I suspected that it was SELinux, but after setting it, it did not work, and the other images also ran normally. I did not have a good idea, so I had to directly change the mount path permission to 777 and start normally (originally it was 755). This operation… Other images have the same permissions.

Error 500 is reported during password initialization after startup

It’s nice to finally get started. However, when initiating the password, I was confused again, and reported Http 500 error directly. The jupyter_Notebook_config. json file cannot be found. This file is the configuration file of jupyter. If this file is not found, the configuration initialization failed. We can initialize it manually, or… Restart the service several times (this is really useful)

Example Manually initialize juptyer configurations

  1. First of all byexecCommand enter container
  2. Execute the commandjupyter lab --generate-config
  3. Change the permissions of all files in the configuration path to777. performchmod 777 .jupyter/*
  4. Out of the container

** Note: ** we do not need to do this again when migrating the server, as our data will be backed up and the configuration files will be included in the backup.

The password does not take effect after startup

After all the configuration, it’s time to initialize the password. When I try to log in again, the message “Invalid Credentials” is displayed. I’m really fucking crazy. Finally, I found a solution. Restart the service twice. GitHub issue

Rubbish!

Is it over? No. When creating a file, a 404 message is displayed

Here I have a heart like calm water, error on error. Dubious!

Fortunately, this problem is relatively easy to fix. Look at the log

[W 13:31:34. 069 LabApp] Blocking Cross Origin API request for/API/contents /. Origin: https://jupyter.fxcdev.com, Host: Toner-jupyter :8888 [W 13:31:34.069 LabApp] Not Found [W 13:31:34.070 LabApp] 404 POST/API /contents/?1573306294042 (1.76 ms referer=https://jupyter.fxcdev.com/lab? 172.28.0.3)Copy the code

It’s cross-domain. Why cross-domain? The domain name changed because nginx forwarded it. Just configure nginx. Proxy_set_header Host $Host; Perfect problem solving.

conclusion

The article is messy, let’s summarize the solution to the problem first:

  1. Docker cannot start after the anonymous coupon is mounted, prompting permission rejection ———— Change the mount path permission to777
  2. 500 error message is reported when the password is set after the system starts ———— Manually initialize the jupyter configuration or restart the system several times
  3. The password does not take effect after the system starts ———— Restart jupyter several times
  4. Error 404 when creating a file ———— When configuring nginx forwarding, bring the domain name

Finally, I can use the environment comfortably. After a while, if I find anything, I will put it out for you to see ~ please look forward to it!