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.
2
Answers
The solution I found is provided by Francois Rivard article here.
[boot]
section perNotTheDr01ds
suggestion.start-notebook.sh
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
andCMD
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):Again not recommended since you cannot (easily) recover or do much of anything else with the instance once you put this in effect.