I used Docker in WSL2 to pull the image jupyter/scipy-notebook
and run it with no problem. Then I exported the image and re-imported it into WSL2 so I can run it directly from WSL.
The issue is that, when I start the image in WSL, it just give me a root prompt. This docker image build must have setup a startup script to run when docker start. Is there a standard location that Docker sets up and runs a startup script?
The Dockerfile for the image on Github shows me that I should run script /usr/local/bin/start-notebook.sh
. However, it failed when I tried. I think I'm missing some startup environment variables.
Any idea of where to look is appreciated.
CodePudding user response:
It seems from your answer that you still have questions, so let me address that part.
Docker knows what to launch at startup using a combination of the ENTRYPOINT
and CMD
settings (which I believe you've already figured out).
When it starts the namespace (container), it passes in the proper command-line.
Interestingly, WSL itself uses some of the very same technologies and techniques as Docker. This is what allows you to run multiple Linux distributions under one WSL2 "virtual machine". Each instance runs (somewhat) isolated in its own namespace.
There are ultimately many ways to launch WSL using a particular commandline. I'll cover a couple here:
The most analogous way to Docker is by starting with
wsl -e sh -lc "/usr/local/bin/start-notebook.sh"
. Since you've defined your environment variables in~/.profile
, you need to runsh
as a login shell in order for~/.profile
to be sourced at startup. That should set the environment variables and run the script successfully.Alternatively, if you are just using this WSL instance for nothing else but running this notebook, then you can simply add
/usr/local/bin/start-notebook.sh
to the bottom of your~/.profile
, below the environment variables.If you want to get back into the shell itself, start WSL using something like
wsl -e bash --noprofile --norc
. This will launch without running any startup scripts.Ehh, the more I think about this one, the more I don't like it, since you can't recover to the shell if you use it. But just for reference, Windows 11 WSL does have a new feature that allows you to run a command when WSL starts. See the [boot] section of
/etc/wsl.conf
for details.To use this for your purpose, you'd need to set the environment variables on the commandline. So your
/etc/wsl.conf
might look something like this (untested):[boot] command="NB_USER=\"jovyan\" NB_UID=\"1000\" /usr/local/bin/start-notebook.sh" # add the rest of the environment variables as well, of course
Again not recommended since you cannot (easily) recover or do much of anything else with the instance once you put this in effect.
CodePudding user response:
The solution I found is provided by Francois Rivard article here.
- Extract the env variables out of the docker image
docker inspect --format="{{range .Config.Env}}{{printf \"export %s\n\" .}}{{end}}" yourContainerName
- Set up wsl to start with user jovyan by default: edit /etc/wsl.conf add info below
[user]
default=jovyan
- edit /etc/profile and add the variable output from step 1. In my case they look something like below. If you're on Win11, you can try adding them to /etc/wsl.conf
[boot]
section perNotTheDr01ds
suggestion.
export PATH=/opt/conda/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
export DEBIAN_FRONTEND=noninteractive
export CONDA_DIR=/opt/conda
export SHELL=/bin/bash
export NB_USER=jovyan
export NB_UID=1000
export NB_GID=100
export LC_ALL=en_US.UTF-8
export LANG=en_US.UTF-8
export LANGUAGE=en_US.UTF-8
export HOME=/home/jovyan
export XDG_CACHE_HOME=/home/jovyan/.cache/
- exit out of wsl
- next time after starting wsl, just run
start-notebook.sh