Skip to content

Local UI to run and train LLMs and diffusion models. Supports GGUF, MLX, Qwen3.8, DeepSeek-V4.1, MiniMax-H3, Gemma 4, FLUX and more.

docker: let the quickstart generate the passwords and print them (#11109)

Daniel Han8e3a0e4c11bb
diff --git a/README.md b/README.md
index 664c5ae8e31..1d09bbb9423 100644
--- a/README.md
+++ b/README.md
@@ -155,15 +155,15 @@ Use our [Docker image](https://hub.docker.com/r/unsloth/unsloth) ```unsloth/unsl
**Linux / WSL (Bash):**
```bash
-docker run -d --gpus all --ipc=host \
+# use -e UNSLOTH_STUDIO_SECURE=1 instead of -p 8000:8000 for a public Cloudflare HTTPS link
+docker run -d --name unsloth --gpus all --ipc=host \
-p 8000:8000 -p 8888:8888 \
- -e UNSLOTH_STUDIO_PASSWORD="mypassword" -e JUPYTER_PASSWORD="mypassword" \
-v "$PWD":/workspace/host \
-v "$HOME/.cache/huggingface":/workspace/.cache/huggingface \
-v unsloth-studio:/opt/unsloth-studio \
- unsloth/unsloth
+ unsloth/unsloth && docker logs -f unsloth
```
-Follow startup with `docker logs -f <container>`, where `<container>` is the ID printed by `docker run -d` or a name from `docker ps`. Studio is at `http://localhost:8000` (user `unsloth`), JupyterLab at `http://localhost:8888`. The two mounts keep different things across `docker rm`: the Hugging Face cache holds models you download (mounting your host cache also reuses what you already have), and the `unsloth-studio` volume holds your accounts, chats and trained models; each image brings its own Studio code, and a volume from an older image is migrated on the first start (its old code is kept under `.unsloth-studio-legacy/`). Tags (`unsloth/unsloth:core` for notebooks only), GPU support and options: [Docker Hub](https://hub.docker.com/r/unsloth/unsloth).
+The log ends with your links and a generated JupyterLab password, plus a generated Studio password on the first run against a new `unsloth-studio` volume; change that one on first sign-in or Studio stops after an hour. A reused volume keeps the password already stored on it, and `docker exec unsloth unsloth studio reset-password --username unsloth` mints a new one and prints it. Ctrl-C stops following the log, not the container; `docker rm -f unsloth` deletes it. The Hugging Face cache keeps your models and the `unsloth-studio` volume keeps your accounts, chats and trained models, both across `docker rm`; a volume from an older image is migrated on first start, its old code kept under `.unsloth-studio-legacy/`. Those ports publish on every interface: on a cloud host add `-e UNSLOTH_STUDIO_SECURE=1`, drop `-p 8000:8000` and bind JupyterLab to `-p 127.0.0.1:8888:8888`, or bind both to `127.0.0.1` and use an SSH tunnel. Tags (`unsloth/unsloth:core` for notebooks only), GPU support and options: [Docker Hub](https://hub.docker.com/r/unsloth/unsloth).
On AMD there is a separate image, [`unsloth/unsloth-rocm`](https://hub.docker.com/r/unsloth/unsloth-rocm), with the run command and the supported cards on its [Docker Hub page](https://hub.docker.com/r/unsloth/unsloth-rocm). It carries the training stack only, so there is no Studio or JupyterLab in it, and it needs native Linux: WSL exposes `/dev/dxg` rather than the `/dev/kfd` that ROCm needs.
diff --git a/docker/DOCKERHUB.md b/docker/DOCKERHUB.md
index eda37c231f0..0b9f81391d2 100644
--- a/docker/DOCKERHUB.md
+++ b/docker/DOCKERHUB.md
@@ -1,57 +1,71 @@
# Unsloth Docker Image
-Pre-built images for [Unsloth](https://github.com/unslothai/unsloth): fine-tune and run LLMs, vision, audio and diffusion models with no setup. Every image carries the full training stack (PyTorch 2.11 with CUDA 12.8, Unsloth, unsloth-zoo, bitsandbytes, TRL, PEFT, plus xformers on `linux/amd64`), JupyterLab with the [Unsloth notebooks](https://github.com/unslothai/notebooks) pre-synced, and prebuilt llama.cpp for GGUF work. The `latest` image adds whisper.cpp for Studio's speech-to-text.
+Fine-tune and run LLMs, vision, audio and diffusion models with no setup. Every image carries the training stack (PyTorch 2.11 with CUDA 12.8, [Unsloth](https://github.com/unslothai/unsloth), unsloth-zoo, bitsandbytes, TRL, PEFT, plus xformers on `linux/amd64`), JupyterLab with the [Unsloth notebooks](https://github.com/unslothai/notebooks), and prebuilt llama.cpp. The `latest` image adds whisper.cpp for Studio's speech-to-text.
-Source: [`docker/`](https://github.com/unslothai/unsloth/tree/main/docker) in the main repository. Guide: [docs.unsloth.ai](https://docs.unsloth.ai/get-started/install/docker).
+Source: [`docker/`](https://github.com/unslothai/unsloth/tree/main/docker). Guide: [docs.unsloth.ai](https://docs.unsloth.ai/get-started/install/docker).
-## Tags
+## Quick start
-| Tag | Contents | Use it for |
-|---|---|---|
-| `latest`, `studio` | Unsloth Studio web UI + JupyterLab + notebooks + key-only SSH | Most users. Train and chat in the browser. |
-| `core` | Training stack + JupyterLab + notebooks, no Studio | Notebooks, scripts, CI, slimmer pulls. |
-| `nightly-<YYYY.MM.DD>`, `core-nightly-<YYYY.MM.DD>` | The same two images, one immutable pin per daily rebuild, kept 60 days | Reproducible runs. |
-| `<version>`, `core-<version>` | Release builds | Pin a release. |
+```bash
+# use -e UNSLOTH_STUDIO_SECURE=1 instead of -p 8000:8000 for a public Cloudflare HTTPS link
+docker run -d --name unsloth --gpus all --ipc=host \
+ --ulimit memlock=-1 --ulimit stack=67108864 \
+ -p 8000:8000 -p 8888:8888 \
+ -v "$PWD":/workspace/host \
+ -v "$HOME/.cache/huggingface":/workspace/.cache/huggingface \
+ -v unsloth-studio:/opt/unsloth-studio \
+ unsloth/unsloth && docker logs -f unsloth
+```
-`latest` and `core` are rebuilt daily and on every release tag, not on every merge to `main`. Both images are multi-arch: `linux/amd64` and `linux/arm64` (GH200, DGX Spark).
+That starts the container and follows its startup, which ends after about a minute with your links and a generated JupyterLab password. On the first run against a new `unsloth-studio` volume it generates a Studio password too; change that one on first sign-in or Studio stops after an hour. Reusing an existing volume keeps the Studio password already stored on it, which the log says rather than printing one. Ctrl-C stops following the log, not the container.
-## Quick start
+Those ports publish on every interface, which is fine on a laptop and not on a cloud host. Three ways to close that, in order of least work:
+
+- `-e UNSLOTH_STUDIO_SECURE=1`, with `-p 8000:8000` dropped and 8888 changed to `-p 127.0.0.1:8888:8888`: Studio is served only over a Cloudflare HTTPS link, printed in the log, and binds to loopback inside the container so no raw port exists. It fails closed, so no tunnel means no link rather than serving in the clear. Move JupyterLab too, or it stays published on every interface over plain HTTP, which is a shell on your GPU box with its password in the clear. On a new volume the public page will not hand out the generated first-boot password, so set one first (see below). `UNSLOTH_STUDIO_CLOUDFLARE=1` keeps the local port as well.
+- Publish to `127.0.0.1` and tunnel: `-p 127.0.0.1:8000:8000 -p 127.0.0.1:8888:8888`, then `ssh -L 8000:localhost:8000 -L 8888:localhost:8888 user@your-host`.
+- Keep the ports and set real passwords with `-e UNSLOTH_STUDIO_PASSWORD=...` and `-e JUPYTER_PASSWORD=...`.
+
+Studio reports on start whether the port answered from the public internet, so you are told either way.
-Needs an NVIDIA driver of 570.26 or newer and, on Linux, Docker plus the NVIDIA Container Toolkit. Without Docker, start here:
+### Before that, on a new machine
+
+Needs an NVIDIA driver of 570.26 or newer. On Linux you also need Docker and the NVIDIA Container Toolkit:
```bash
curl -fsSL https://get.docker.com -o get-docker.sh && sh get-docker.sh
+curl -fsSL https://raw.githubusercontent.com/unslothai/unsloth/main/docker/install_nvidia_toolkit.sh -o install_nvidia_toolkit.sh && sudo -E bash install_nvidia_toolkit.sh
```
-Then one command installs the toolkit (Ubuntu, Debian, RHEL, Fedora, Rocky, Amazon Linux, SUSE) and checks a container can see the GPU:
+The second command covers Ubuntu, Debian, RHEL, Fedora, Rocky, Amazon Linux and SUSE, and checks that a container can see the GPU. On Windows, Docker Desktop with the WSL 2 backend and a current NVIDIA Windows driver is all you need; run the quick start above in a WSL 2 shell.
+
+Or let `run.sh` set the quick start's flags, including the `unsloth-studio` volume, for you. It offers to install the toolkit if the daemon has no `nvidia` runtime:
```bash
-curl -fsSL https://raw.githubusercontent.com/unslothai/unsloth/main/docker/install_nvidia_toolkit.sh -o install_nvidia_toolkit.sh && sudo -E bash install_nvidia_toolkit.sh
+curl -fsSL https://raw.githubusercontent.com/unslothai/unsloth/main/docker/run.sh -o run.sh
+UNSLOTH_PORTS="-p 8000:8000 -p 8888:8888" bash run.sh
```
-On Windows use Docker Desktop with the WSL 2 backend and a current NVIDIA Windows driver; nothing else to install. Then:
+### Resetting the password
```bash
-docker run -d --gpus all --ipc=host \
- --ulimit memlock=-1 --ulimit stack=67108864 \
- -p 8000:8000 -p 8888:8888 \
- -e UNSLOTH_STUDIO_PASSWORD="choose-a-password" \
- -e JUPYTER_PASSWORD="choose-a-password" \
- -v "$PWD":/workspace/host \
- -v "$HOME/.cache/huggingface":/workspace/.cache/huggingface \
- -v unsloth-studio:/opt/unsloth-studio \
- unsloth/unsloth
+docker exec unsloth unsloth studio reset-password --username unsloth
```
-`docker run -d` returns at once; follow the startup with `docker logs -f <container>`, which ends with a ready block once both services answer (Studio takes about a minute). Then open Studio at `http://localhost:8000` (user `unsloth`) and JupyterLab at `http://localhost:8888`. Leave either password variable unset and a random one is generated and printed in that log.
+It mints a new password and prints it, revokes sessions and API keys, and rotates in place, so nothing needs restarting. `--username` is required once more than one account exists and harmless before that. Shared `/p` preview links are not revoked; rotate those in Settings if the old password leaked.
-Or let `run.sh` set these flags, including the `unsloth-studio` volume, for you. It offers to install the NVIDIA Container Toolkit if the daemon has no `nvidia` runtime:
+### Stopping and removing it
```bash
-curl -fsSL https://raw.githubusercontent.com/unslothai/unsloth/main/docker/run.sh -o run.sh
-UNSLOTH_PORTS="-p 8000:8000 -p 8888:8888" bash run.sh
+docker stop unsloth # shut it down, keep it
+docker start unsloth # bring it back, same state
+docker rm -f unsloth # stop and delete the container
+docker ps -a # find it again, running or not
```
+`docker rm -f` deletes the container, not your work: models stay in the Hugging Face cache, your files in the directory you mounted, and Studio's accounts and chats on the `unsloth-studio` volume, so the next container with the same `-v unsloth-studio:/opt/unsloth-studio` resumes where this one left off, password included. Only what was written inside the container is lost. `docker volume rm unsloth-studio` discards the Studio data too, and cannot be undone.
+
+These take a container, not an image, so `docker stop unsloth/unsloth` fails with "No such container". Use the `NAMES` or `CONTAINER ID` column of `docker ps -a`; without `--name`, Docker assigns a random one.
+
### Notebooks only (`core`)
The `core` image has no service manager. Start JupyterLab on the command line:
@@ -81,17 +95,24 @@ docker run -d -p 8000:8000 -p 8888:8888 unsloth/unsloth
docker run --rm -e UNSLOTH_ALLOW_CPU=1 unsloth/unsloth:core python -c "import unsloth"
```
-## Supported GPUs
+## Tags
-Turing (T4, RTX 20), Ampere (A100, A10, RTX 30), Ada (L4, L40, RTX 40), Hopper (H100, H200, GH200) and Blackwell (B200, GB200, RTX 50, RTX PRO 6000) all run precompiled SASS. The cu128 wheels the image ships carry native SASS for `sm_70 sm_75 sm_80 sm_86 sm_90 sm_100 sm_120` on `linux/amd64` and `sm_80 sm_90 sm_90a sm_100 sm_100a sm_120 sm_120a` on `linux/arm64`; SASS is forward-compatible within a major version, so Ada runs the `sm_86` binaries and B300 and GB300 run the `sm_100` ones. A source build inside the image is a separate matter: it compiles for `7.5;8.0;8.6;8.9;9.0;10.0;12.0+PTX` on either architecture. GB10 (DGX Spark, `sm_121`) runs the `sm_120` binaries through Blackwell forward compatibility; only kernels compiled at run time, such as Triton, use the CUDA 13 compiler the container switches to on that GPU. The container prints the detected GPU on start and explains what to do when the driver is too old.
+| Tag | Contents | Use it for |
+|---|---|---|
+| `latest`, `studio` | Unsloth Studio web UI + JupyterLab + notebooks + key-only SSH | Most users. Train and chat in the browser. |
+| `core` | Training stack + JupyterLab + notebooks, no Studio | Notebooks, scripts, CI, slimmer pulls. |
+| `nightly-<YYYY.MM.DD>`, `core-nightly-<YYYY.MM.DD>` | The same two images, one immutable pin per daily rebuild, kept 60 days | Reproducible runs. |
+| `<version>`, `core-<version>` | Release builds | Pin a release. |
+
+`latest` and `core` are rebuilt daily and on every release tag, not on every merge to `main`. Both are multi-arch: `linux/amd64` and `linux/arm64` (GH200, DGX Spark).
-Driver requirements:
+## Supported GPUs
-- 570.26 or newer for CUDA 12.8 on every GPU.
-- 580 or newer for B300, GB300 and GB10.
-- On `linux/arm64` the bundled llama.cpp is a CUDA 13 build because upstream ships no CUDA 12 build for that architecture. Training works from driver 570, but GGUF export and Studio chat need 580 or newer.
+Turing (T4, RTX 20) through Blackwell (B200, GB200, RTX 50, RTX PRO 6000) run precompiled SASS: `sm_70 sm_75 sm_80 sm_86 sm_90 sm_100 sm_120` on `linux/amd64`, `sm_80 sm_90 sm_90a sm_100 sm_100a sm_120 sm_120a` on `linux/arm64`. SASS is forward-compatible within a major version, so Ada runs the `sm_86` binaries, B300 and GB300 the `sm_100` ones, and GB10 (DGX Spark) the `sm_120` ones. A source build inside the image compiles for `7.5;8.0;8.6;8.9;9.0;10.0;12.0+PTX`.
-Turing has no bfloat16; Unsloth falls back to float16 there. These images are CUDA only; for AMD use [`unsloth/unsloth-rocm`](https://hub.docker.com/r/unsloth/unsloth-rocm), which carries a ROCm build of the training stack.
+Drivers: 570.26 or newer for CUDA 12.8 on every GPU, 580 or newer for B300, GB300 and GB10. On `linux/arm64` the bundled llama.cpp is a CUDA 13 build, because upstream ships no CUDA 12 one there, so training works from 570 but GGUF export and Studio chat need 580.
+
+Turing has no bfloat16; Unsloth falls back to float16 there. These images are CUDA only; for AMD use [`unsloth/unsloth-rocm`](https://hub.docker.com/r/unsloth/unsloth-rocm), a ROCm build of the training stack.
## Ports
@@ -105,20 +126,19 @@ Turing has no bfloat16; Unsloth falls back to float16 there. These images are CU
| Variable | Effect |
|---|---|
-| `UNSLOTH_STUDIO_PASSWORD` | Initial Studio admin password for user `unsloth`; ignored once a password is stored. Unset: generated once and printed in the logs, and Studio stops after an hour unless it is changed (`UNSLOTH_STUDIO_BOOTSTRAP_TIMEOUT=0` disables). |
-| `JUPYTER_PASSWORD` | JupyterLab password, read by the `latest` service launcher. Unset: generated once and printed in the logs. On `core` you start JupyterLab yourself, so pass its own flags instead. |
-| `JUPYTER_PORT` | JupyterLab port inside the container, read by the `latest` service launcher. Default `8888`. `8000` is refused: that is Studio's port inside the container. |
-| `SSH_KEY` or `PUBLIC_KEY` | OpenSSH public key for root login. Enables sshd on port 22. Password login is never enabled. |
+| `UNSLOTH_STUDIO_PASSWORD` | Initial Studio password for user `unsloth`; ignored once one is stored. Unset: generated, printed in the logs, and Studio stops after an hour unless changed (`UNSLOTH_STUDIO_BOOTSTRAP_TIMEOUT=0` disables). |
+| `JUPYTER_PASSWORD` | JupyterLab password, read by the `latest` launcher. Unset: generated and printed in the logs. On `core` you start JupyterLab yourself. |
+| `JUPYTER_PORT` | JupyterLab's port inside the container. Default `8888`. `8000` is refused: that is Studio's. |
+| `SSH_KEY` or `PUBLIC_KEY` | OpenSSH public key for root login; enables sshd on port 22. Password login is never enabled. |
| `UNSLOTH_ALLOW_CPU=1` | Allow starting without a GPU (`latest` already does). Dropped when a GPU is visible, where it would turn off Unsloth's training patches. |
+| `UNSLOTH_STUDIO_SECURE=1` | Serve Studio over a Cloudflare HTTPS link only, bound to loopback inside the container so no raw port is published. Fails closed if the tunnel does not come up. |
+| `UNSLOTH_STUDIO_CLOUDFLARE=1` | The same HTTPS link, with the local port still served. Not valid together with `UNSLOTH_STUDIO_SECURE=1`. |
| `UNSLOTH_JUPYTER_CLOUDFLARE=1` | Publish JupyterLab through a Cloudflare quick tunnel and print the URL. |
| `UNSLOTH_SKIP_NOTEBOOK_REFRESH=1` | Do not refresh the notebooks from GitHub on start; the copy baked into the image is still used. |
-| `UNSLOTH_SKIP_NOTEBOOK_SYNC=1` | Do not set up the notebooks at all: nothing is created at `/workspace/unsloth-notebooks` or `/workspace/Unsloth Notebooks` (copies left there by an earlier start on a mounted `/workspace` stay as they are). |
+| `UNSLOTH_SKIP_NOTEBOOK_SYNC=1` | Do not set up the notebooks at all: nothing is created at `/workspace/unsloth-notebooks` or `/workspace/Unsloth Notebooks`. |
| `HF_TOKEN`, `WANDB_API_KEY` | Forwarded to Hugging Face and Weights and Biases. |
-On a host with no GPU, Studio, JupyterLab and its kernels, and login shells all run in
-CPU mode. A non-login `docker exec` is built from the image, not the container's first
-process, so `docker exec <c> python -c "import unsloth"` still reports that it needs a
-GPU: use `docker exec <c> bash -lc '...'` or `docker exec -e UNSLOTH_ALLOW_CPU=1 <c> ...`.
+On a CPU-only host a non-login `docker exec` is built from the image, not the container's first process, so `docker exec <c> python -c "import unsloth"` still asks for a GPU. Use `bash -lc '...'` or pass `-e UNSLOTH_ALLOW_CPU=1`.
## Volumes
@@ -128,7 +148,7 @@ The working directory is `/workspace`. Mount what you want to keep:
|---|---|
| `/workspace/host` | Your files. Mount your project directory here. |
| `/workspace/.cache/huggingface` | Model downloads. Mount your host HF cache to reuse it. |
-| `/opt/unsloth-studio` | Studio's accounts, chats, outputs, exports and runs (`latest`). Use a named volume: without one, `docker rm` loses them. A new image still brings new Studio code (see below). |
+| `/opt/unsloth-studio` | Studio's accounts, chats, outputs, exports and runs (`latest`). Use a named volume: without one, `docker rm` loses them. |
| `/workspace/.cache/triton` | Compiled kernels. Optional, speeds up restarts. |
| `/workspace/unsloth-notebooks` | The synced notebooks. Your edits are kept across refreshes. |
| `/workspace/Unsloth Notebooks` | The same notebooks grouped by topic, rebuilt on each start. |
@@ -137,24 +157,20 @@ The container runs as root by default. On `core`, `--user <uid>:<gid>` is suppor
### Studio data and Studio code
-Studio's code (its venv, source tree, Node, prebuilt tools) ships in the image under `/opt/unsloth-studio-app` and is linked into `/opt/unsloth-studio` at every start, so the volume holds only your data and every image runs its own code. What that means in practice:
+Studio's code ships in the image under `/opt/unsloth-studio-app` and is linked into `/opt/unsloth-studio` at every start, so the volume holds only your data and every image runs its own code.
-- A volume created by an image from before this split holds that image's code as real directories. The first start of a newer image moves each of them aside to `/opt/unsloth-studio/.unsloth-studio-legacy/<name>` on the volume and links the new code in; nothing is deleted, and the log lists what moved. Delete the legacy directory once the new image works (`docker exec <c> rm -rf /opt/unsloth-studio/.unsloth-studio-legacy`), or start with `-e UNSLOTH_STUDIO_KEEP_LEGACY=0` to skip keeping it. Such a volume also holds that image's uv download cache at `/opt/unsloth-studio/cache/uv` (about 9 GB, hardlinked with the legacy venv); once the legacy directory is gone, `rm -rf /opt/unsloth-studio/cache/uv` frees it.
-- To go back to an image from before the split on the same volume, move the legacy entries back first: `docker run --rm -v unsloth-studio:/h alpine sh -c 'cd /h && for e in .unsloth-studio-legacy/* .unsloth-studio-legacy/.[!.]*; do [ -e "$e" ] || [ -L "$e" ] || continue; rm -rf "${e##*/}"; mv "$e" .; done'`. Images from after the split need nothing. A volume that never held old code (first used after the split, or its legacy directory deleted) gets a copy of the current image's code instead: `docker run --rm -v unsloth-studio:/opt/unsloth-studio --entrypoint unsloth-studio-home <current image> --restore` (about 5 GB, half a minute), after which the older image runs it.
-- `docker rm` still discards anything written into the image's copy: an in-container `unsloth-studio-update` and the `cloudflared` binary `unsloth-jupyter-tunnel` downloads. Studio's caches under `/opt/unsloth-studio/cache` (download resume state, dataset caches) are in the home, so they stay with the volume. Models stay in the Hugging Face cache mount.
-- Use a named volume, not a bind mount of a Windows or macOS host directory. The Studio home needs symlinks, and bind mounts through Docker Desktop's file sharing (a Windows drive under WSL 2 in particular) may refuse to create them; the container then stops at start with the linker's error instead of running a half-linked Studio. A bind mount of a Linux directory (including a directory inside the WSL 2 distribution) works.
+- A volume from before that split holds an old image's code. The first start of a newer image moves it aside to `/opt/unsloth-studio/.unsloth-studio-legacy/` and links the new code in; nothing is deleted. Delete it once the new image works (`docker exec <c> rm -rf /opt/unsloth-studio/.unsloth-studio-legacy`), along with the 9 GB uv cache at `/opt/unsloth-studio/cache/uv`, or start with `-e UNSLOTH_STUDIO_KEEP_LEGACY=0` to skip keeping it. Going back to a pre-split image needs those entries moved back, or `docker run --rm -v unsloth-studio:/opt/unsloth-studio --entrypoint unsloth-studio-home <current image> --restore`.
+- Use a named volume, not a bind mount of a Windows or macOS host directory: the Studio home needs symlinks, and Docker Desktop's file sharing may refuse to create them, stopping the container at start. A Linux directory, including one inside a WSL 2 distribution, works.
## Updating inside a running container
On the `latest` image:
-- `unsloth-studio-update` upgrades Studio and Unsloth in place, leaving the torch and CUDA stack pinned (in the image's copy: survives `docker restart`, not `docker rm`).
+- `unsloth-studio-update` upgrades Studio and Unsloth in place, leaving the torch and CUDA stack pinned. It survives `docker restart`, not `docker rm`.
- `unsloth-llama-update` fetches the newest prebuilt llama.cpp.
-- `unsloth-jupyter-tunnel --force` opens a Cloudflare quick tunnel to JupyterLab. Without `--force`, and without `UNSLOTH_JUPYTER_CLOUDFLARE=1` in the environment, it prints that it is disabled and exits.
-
-On both images the notebooks refresh from GitHub on each start unless `UNSLOTH_SKIP_NOTEBOOK_REFRESH=1`. Pull a new image tag to update everything else.
+- `unsloth-jupyter-tunnel --force` opens a Cloudflare quick tunnel to JupyterLab. Without `--force` or `UNSLOTH_JUPYTER_CLOUDFLARE=1` it prints that it is disabled and exits.
-Setting them up costs roughly 10 to 20 seconds of every start, depending on the disk, so a one-shot `docker run --rm ... python script.py` is worth running with `UNSLOTH_SKIP_NOTEBOOK_SYNC=1`.
+Both images refresh the notebooks from GitHub on each start, which costs 10 to 20 seconds, so a one-shot `docker run --rm ... python script.py` is worth running with `UNSLOTH_SKIP_NOTEBOOK_SYNC=1`. Pull a new image tag to update everything else.
## Help
diff --git a/docker/run.sh b/docker/run.sh
index e1ab70456ea..b7833b1b66d 100755
--- a/docker/run.sh
+++ b/docker/run.sh
@@ -312,6 +312,11 @@ declare -a ENV_FORWARD=(-e HF_HUB_ENABLE_HF_TRANSFER=1)
[[ -n "${PUBLIC_KEY:-}" ]] && ENV_FORWARD+=(-e PUBLIC_KEY)
[[ -n "${SSH_KEY:-}" ]] && ENV_FORWARD+=(-e SSH_KEY)
[[ -n "${UNSLOTH_JUPYTER_CLOUDFLARE:-}" ]] && ENV_FORWARD+=(-e UNSLOTH_JUPYTER_CLOUDFLARE)
+# Studio's two exposure modes, read by studio_run.sh inside the container. The
+# allowlist is explicit, so leaving them out made both silently inert through the
+# helper the documentation recommends.
+[[ -n "${UNSLOTH_STUDIO_SECURE:-}" ]] && ENV_FORWARD+=(-e UNSLOTH_STUDIO_SECURE)
+[[ -n "${UNSLOTH_STUDIO_CLOUDFLARE:-}" ]] && ENV_FORWARD+=(-e UNSLOTH_STUDIO_CLOUDFLARE)
declare -a PORT_FLAGS=()
if [[ -n "${UNSLOTH_PORTS:-}" ]]; then
diff --git a/docker/studio_launch.sh b/docker/studio_launch.sh
index fd0989f18c1..a75506341b9 100644
--- a/docker/studio_launch.sh
+++ b/docker/studio_launch.sh
@@ -90,10 +90,17 @@ EOF
UNSLOTH_VIEW_REL="${_view_rel}" UNSLOTH_VIEW_DIR="${_view_dir}" \
python - >> "${JUPYTER_CONFIG_DIR}/jupyter_lab_config.py" <<'PY'
import os
+import urllib.parse
rel = os.environ["UNSLOTH_VIEW_REL"]
view = os.environ["UNSLOTH_VIEW_DIR"]
-print(f"c.ServerApp.default_url = {'/lab/tree/' + rel!r}")
-print(f"c.LabApp.default_url = {'/lab/tree/' + rel!r}")
+# default_url is a URL, not a path: the default view directory has a space in it,
+# and unencoded it lands in the banner Jupyter prints as
+# "http://host:8888/lab/tree/Unsloth Notebooks", which is not copy-pasteable and
+# is not a legal request target. Measured: curl refuses the raw form outright and
+# gets 302 from the encoded one. quote() leaves "/" alone, so subdirectories keep working.
+url = "/lab/tree/" + urllib.parse.quote(rel)
+print(f"c.ServerApp.default_url = {url!r}")
+print(f"c.LabApp.default_url = {url!r}")
print(f"c.ServerApp.preferred_dir = {view!r}")
PY
fi
diff --git a/docker/studio_password.sh b/docker/studio_password.sh
index 3d940da49be..967511dc560 100755
--- a/docker/studio_password.sh
+++ b/docker/studio_password.sh
@@ -100,10 +100,20 @@ studio_text="not answering"
[[ -n "$studio_ok" ]] && studio_text="$STUDIO_LINE"
jupyter_text="not answering"
[[ -n "$jupyter_ok" ]] && jupyter_text="${UNSLOTH_JUPYTER_NOTE:-password from JUPYTER_PASSWORD env}"
+# This block is the only part of a long startup log the reader needs, and plain
+# echo left it indistinguishable from the supervisord and Jupyter noise around
+# it, so the URLs and the generated passwords went unread. Colour the rules and
+# title, the links, and the two credential fields. NO_COLOR (no-color.org) turns
+# it off for anything collecting these logs into a file.
+if [[ -n "${NO_COLOR:-}" ]]; then
+ _b=""; _g=""; _y=""; _r=""
+else
+ _b=$'\033[1m'; _g=$'\033[1;32m'; _y=$'\033[1;33m'; _r=$'\033[0m'
+fi
rule="$(printf '=%.0s' $(seq 1 72))"
-echo "$rule"
-echo " ${title}"
-echo " Studio http://localhost:8000 ${studio_text}"
-echo " JupyterLab http://localhost:${JUPYTER_PORT} ${jupyter_text}"
-echo " Ports are the container's: use the host side of your -p flags, or an SSH tunnel to a remote host."
-echo "$rule"
+printf '%s\n' "${_g}${rule}${_r}"
+printf ' %s\n' "${_g}${title}${_r}"
+printf ' Studio %s %s\n' "${_b}http://localhost:8000${_r}" "${_y}${studio_text}${_r}"
+printf ' JupyterLab %s %s\n' "${_b}http://localhost:${JUPYTER_PORT}${_r}" "${_y}${jupyter_text}${_r}"
+printf ' %s\n' "Ports are the container's: use the host side of your -p flags, or an SSH tunnel to a remote host."
+printf '%s\n' "${_g}${rule}${_r}"
diff --git a/docker/studio_run.sh b/docker/studio_run.sh
index 8efebc02296..7744b475162 100644
--- a/docker/studio_run.sh
+++ b/docker/studio_run.sh
@@ -69,4 +69,30 @@ if [[ -s "$INITIAL" ]] && ! password_stored; then
IFS= read -r -d '' UNSLOTH_STUDIO_PASSWORD < "$INITIAL" || true
export UNSLOTH_STUDIO_PASSWORD
fi
-exec "${STUDIO_HOME}/bin/unsloth" studio -H 0.0.0.0 -p 8000
+# Exposure. The default stays -H 0.0.0.0 because that is what makes a published
+# -p 8000:8000 reachable at all; the container is the boundary, the host's -p
+# decides who sees it.
+#
+# UNSLOTH_STUDIO_SECURE=1 --secure: a Cloudflare HTTPS link and nothing
+# else. Studio forces a loopback bind itself, so
+# -p 8000:8000 would publish a port nothing is
+# listening on. Fails closed if the tunnel does
+# not come up.
+# UNSLOTH_STUDIO_CLOUDFLARE=1 --cloudflare: the same public HTTPS link, with
+# the local port still served, for a laptop that
+# wants both.
+#
+# Mirrors UNSLOTH_JUPYTER_CLOUDFLARE, which JupyterLab has had all along. The two
+# are mutually exclusive in the CLI, so refuse the pair here rather than let
+# supervisord restart Studio forever on an argument error.
+STUDIO_ARGS=(-H 0.0.0.0 -p 8000)
+if [[ "${UNSLOTH_STUDIO_SECURE:-0}" == "1" && "${UNSLOTH_STUDIO_CLOUDFLARE:-0}" == "1" ]]; then
+ echo "ERROR: set UNSLOTH_STUDIO_SECURE=1 or UNSLOTH_STUDIO_CLOUDFLARE=1, not both:" >&2
+ echo " --secure serves only the tunnel, --cloudflare serves the tunnel and the local port." >&2
+ exit 2
+elif [[ "${UNSLOTH_STUDIO_SECURE:-0}" == "1" ]]; then
+ STUDIO_ARGS=(--secure -p 8000)
+elif [[ "${UNSLOTH_STUDIO_CLOUDFLARE:-0}" == "1" ]]; then
+ STUDIO_ARGS+=(--cloudflare)
+fi
+exec "${STUDIO_HOME}/bin/unsloth" studio "${STUDIO_ARGS[@]}"
diff --git a/tests/python/test_docker_studio_launch_view_config.py b/tests/python/test_docker_studio_launch_view_config.py
index bf751d5c36a..5534be71660 100644
--- a/tests/python/test_docker_studio_launch_view_config.py
+++ b/tests/python/test_docker_studio_launch_view_config.py
@@ -26,6 +26,7 @@ import types
from pathlib import Path
import pytest
+import urllib.parse
REPO_ROOT = Path(__file__).resolve().parents[2]
LAUNCH = REPO_ROOT / "docker" / "studio_launch.sh"
@@ -91,7 +92,12 @@ def test_the_config_stays_valid_python_and_keeps_the_path(generator: str, name:
assert (
config.ServerApp.preferred_dir == view
), "the path Jupyter ends up with must be the one the user asked for"
- assert config.ServerApp.default_url == f"/lab/tree/{name}"
+ # default_url is a URL, not a path: the default view directory has a space in
+ # it, and unencoded it reached the banner Jupyter prints as
+ # "http://host:8888/lab/tree/Unsloth Notebooks", which is not a legal request
+ # target. quote() leaves "/" alone, so subdirectories still resolve.
+ assert config.ServerApp.default_url == "/lab/tree/" + urllib.parse.quote(name)
+ assert " " not in config.ServerApp.default_url, "an unencoded space breaks the printed link"
assert (
config.LabApp.default_url == config.ServerApp.default_url
), "LabApp otherwise overrides ServerApp back to /lab"
diff --git a/tests/python/test_docker_studio_password_banner.py b/tests/python/test_docker_studio_password_banner.py
index e1ac9d37d63..e97883ad722 100644
--- a/tests/python/test_docker_studio_password_banner.py
+++ b/tests/python/test_docker_studio_password_banner.py
@@ -104,6 +104,10 @@ def _run(
UNSLOTH_STUDIO_HOME = str(home),
UNSLOTH_STUDIO_PASSWORD_WAIT = wait,
UNSLOTH_STUDIO_READY_WAIT = "2",
+ # The summary is coloured, which splits the lines these tests match on.
+ # Assert the text here and the colour in its own test below, so a change
+ # to either one fails for the right reason.
+ NO_COLOR = "1",
)
e.update(env or {})
return subprocess.run(["bash", str(SCRIPT)], capture_output = True, text = True, env = e, timeout = 60)
@@ -469,3 +473,17 @@ def test_the_image_wires_the_scripts_in():
"first-boot password below" not in launch
), "the banner promises what Studio no longer prints"
assert "unset UNSLOTH_STUDIO_PASSWORD" in launch
+
+
+def test_the_summary_is_coloured_unless_no_color_is_set(tmp_path: Path):
+ """The block is the one thing worth reading in a long startup log; plain text
+ left it indistinguishable from the supervisord and Jupyter lines around it.
+ NO_COLOR (no-color.org) is the documented way off, for log collectors."""
+ env = {"UNSLOTH_STUDIO_PASSWORD_STATE": "generated"}
+ a, b = tmp_path / "a", tmp_path / "b"
+ a.mkdir()
+ b.mkdir()
+ coloured = _run(a, env = {**env, "NO_COLOR": ""})
+ plain = _run(b, env = env)
+ assert "\033[1;32m" in coloured.stdout.replace("\x1b", "\033"), coloured.stdout
+ assert "\x1b[" not in plain.stdout, plain.stdout