Mike Levin SEO

Future-proof your technology-skills with Linux, Python, vim & git... and me!

← Developing Priceless and Timeless Tech Habits
Switching From WSL to LXD Containers Permanently →

Going Down the WSL to LXD Install Script Rabbit Hole

by Mike Levin

Monday, September 12, 2022

Okay, I set my journal startup to go right to my MikeLev.in blog because it makes for better videos, and that rabbit! It’s really good branding. It differentiates me quite nicely. Nobody has that rabbit facing that direction because I reversed the original artwork.

Hmmm, there’s really so much potential of what to do. What NOT to do. Okay, think it through clearly. One way to smash this thing is to movement-atize all my latest work, and those few install scripts (I’ve already begun) can go a long way.

Following onto an idea I haven’t even published yet is the concept that the combination of changing expectations brought about by Docker, WSL and containers in general, no single Linux instance should be thought of as all that important. You can get it back from either a backup of the image or from a relatively simple server build script.

You don’t want to start working on preserving any particular container image until you have the server build scripts solid. That’s where the specialness really resides. The server-build scripts are the interesting the magic spells for people like me who don’t want deeper into the arcana or higher into the dockersphere.

So currently there’s really nothing special about my jupyter lxd instance. Let’s make a bash install script that will just create a new instance of a Jupyter server fully running and working on localhost:8888 on the Windows machine. Wow, nailed it! This gets installed from an Ubuntu 18.04 instance with LXD running. I should make a PowerShell script to do that next.

#!/usr/bin/env bash

CONTAINERS="$(lxc ls -c "n" --format csv | grep jupyter)"

for container in $CONTAINERS; do
  echo "Stopping $container..."
  lxc stop $container

JUPYTER_EXISTS="$(lxc ls -c "n" --format csv | grep jupyter)"

if [ "$JUPYTER_EXISTS" == "jupyter" ]; then
  lxc delete jupyter --force
  echo "Old Jupyter container deleted."
  echo "jupyter container doesn't exist"

lxc launch ubuntu:18.04 jupyter
lxc config device add jupyter jupyme proxy listen=tcp: connect=tcp:

until [ ! -z "$(lxc ls jupyter -c '4' --format csv)" ]
  sleep 2

lxc exec jupyter -- apt update
lxc exec jupyter -- apt upgrade -y
lxc exec jupyter -- mkdir /home/ubuntu/repos
lxc exec jupyter -- add-apt-repository ppa:deadsnakes/ppa -y
lxc exec jupyter -- apt install python3.10 -y
lxc exec jupyter -- apt install python3.10-venv -y
lxc exec jupyter -- python3.10 -m venv /home/ubuntu/py310
lxc exec jupyter -- curl -L -o /home/ubuntu/.bash_profile "https://raw.githubusercontent.com/miklevin/dotconfigs/main/.bash_profile"
lxc exec jupyter -- curl -L -o /home/ubuntu/.bash_prompt "https://raw.githubusercontent.com/miklevin/dotconfigs/main/.bash_prompt"
lxc exec jupyter -- /home/ubuntu/py310/bin/python3.10 -m pip install jupyterlab
lxc exec jupyter -- chmod -R 777 /home/ubuntu/py310
lxc exec jupyter -- chmod -R 777 /home/ubuntu/repos

Simply logging into this machine with:

lxc exec jupyter -- su --login ubuntu

…will cause the Jupyter server to be running. I don’t think my .bash files belong in that dotconfig repo anymore. I think I should round everything up into a repo names, oh maybe jupyn! That’s my first instinct.

Now is the time to change my big master ~/github folder to ~/repos. Just go for it. 1, 2, 3… 1? Okay, I changed a whole bunch of references from github to repos. Now go into repos and make a jupyme folder… or is that JupWyn? Wow, I want to write jupyme. It flows better. Check the googles for which is less taken. Yeah, change of decision. We’re definitely going with jupyme. It just rolls off the tongue better.

Okay, wow, I got my first version of the Jupyter install script on WSL pretty well worked out. You need to already have LXD on WSL and maybe I’ll do a script for that next.