# Wie man LLMs mit Unsloth und Docker feinabstimmt

Lokales Training kann aufgrund von Abhängigkeitsproblemen oder kaputten Umgebungen komplex sein. Unsloths [Docker-Image](https://hub.docker.com/r/unsloth/unsloth) kann diese Probleme umgehen. Keine Einrichtung erforderlich: Ziehen Sie das Image und starten Sie es, um mit dem Training zu beginnen.

* **Offizielles Unsloth-Docker-Image:** [**`unsloth/unsloth`**](https://hub.docker.com/r/unsloth/unsloth)

**Warum Unsloth & Docker verwenden?**

Unsloths Docker-Image ist stabil, aktuell und funktioniert in [unterstützten Setups](/docs/de/loslegen/fine-tuning-for-beginners/unsloth-requirements.md#system-requirements) wie Windows.

* Vollständig enthaltene Abhängigkeiten halten Ihr System sauber. Läuft sicher ohne Root-Rechte.
* Lokal oder auf jeder Plattform mit vorinstallierten Notebooks verwenden.

{% hint style="success" %}
Sie können jetzt unser Haupt-Docker-Image `unsloth/unsloth` für Blackwell- und 50er-GPUs verwenden – kein separates Image erforderlich.
{% endhint %}

### ⚡ Schritt-für-Schritt-Anleitung

{% stepper %}
{% step %}
**Installieren Sie Docker und das NVIDIA Container Toolkit.**

Installieren Sie Docker über [Linux](https://docs.docker.com/engine/install/) oder [Desktop](https://docs.docker.com/desktop/) (andere).\
Installieren Sie dann [NVIDIA Container Toolkit](https://docs.nvidia.com/datacenter/cloud-native/container-toolkit/latest/install-guide.html#installation):

<pre class="language-bash"><code class="lang-bash"><strong>export NVIDIA_CONTAINER_TOOLKIT_VERSION=1.17.8-1
</strong>sudo apt-get update &#x26;&#x26; sudo apt-get install -y \
  nvidia-container-toolkit=${NVIDIA_CONTAINER_TOOLKIT_VERSION} \
  nvidia-container-toolkit-base=${NVIDIA_CONTAINER_TOOLKIT_VERSION} \
  libnvidia-container-tools=${NVIDIA_CONTAINER_TOOLKIT_VERSION} \
  libnvidia-container1=${NVIDIA_CONTAINER_TOOLKIT_VERSION}
</code></pre>

<figure><img src="/files/158ec1548eb656f7fdaea4e230d38c745d02ffc7" alt=""><figcaption></figcaption></figure>
{% endstep %}

{% step %}
**Starten Sie den Container.**

[**`unsloth/unsloth`**](https://hub.docker.com/r/unsloth/unsloth) ist Unsloths einziges Docker-Image. Für [Blackwell](/docs/de/blog/fine-tuning-llms-with-blackwell-rtx-50-series-and-unsloth.md) und 50er-GPUs verwenden Sie dasselbe Image – kein separates Image erforderlich. Wenn Sie DGX Spark verwenden, müssen Sie unserer [DGX-Anleitung](/docs/de/blog/fine-tuning-llms-with-nvidia-dgx-spark-and-unsloth.md).

```bash
docker run -d -e JUPYTER_PASSWORD="mypassword" \
  -p 8888:8888 -p 2222:22 \
  -v $(pwd)/work:/workspace/work \
  --gpus all \
  unsloth/unsloth
```

<figure><img src="/files/b25537a28700f0cc8b7689bd7559e6ef68ffaada" alt=""><figcaption></figcaption></figure>
{% endstep %}

{% step %}
**Zugriff auf Jupyter Lab**

Gehen Sie zu [http://localhost:8888](http://localhost:8888/) und öffnen Sie Unsloth.

<figure><img src="/files/670d35954fa5278dd2f2e40b239a10d0a96d2ead" alt="" width="563"><figcaption></figcaption></figure>

Greifen Sie auf die `unsloth-notebooks` Registerkarten zu, um Unsloth-Notebooks zu sehen.

<div><figure><img src="/files/c646de7ce04bbd4bb333d2d37dfe09a907f917e4" alt=""><figcaption></figcaption></figure> <figure><img src="/files/9c05b7ab3463590f0aaecdfe3541d7eb8705ed3c" alt=""><figcaption></figcaption></figure></div>
{% endstep %}

{% step %}
**Beginnen Sie mit dem Training mit Unsloth**

Wenn Sie neu sind, folgen Sie unserer Schritt-für-Schritt- [Feinabstimmungsanleitung](/docs/de/loslegen/fine-tuning-llms-guide.md), [RL-Anleitung](/docs/de/loslegen/reinforcement-learning-rl-guide.md) oder speichern/kopieren Sie einfach eines unserer vorgefertigten [Notebooks](/docs/de/loslegen/unsloth-notebooks.md).

<figure><img src="/files/fb4b91a23e24279223cbfbe87ce34b04eea0d75a" alt=""><figcaption></figcaption></figure>
{% endstep %}
{% endstepper %}

#### 📂 Container-Struktur

* `/workspace/work/` — Ihr eingehängtes Arbeitsverzeichnis
* `/workspace/unsloth-notebooks/` — Beispiel-Notebooks zur Feinabstimmung
* `/home/unsloth/` — Benutzer-Home-Verzeichnis

### 📖 Nutzungsbeispiel

#### Vollständiges Beispiel

```bash
docker run -d -e JUPYTER_PORT=8000 \
  -e JUPYTER_PASSWORD="mypassword" \
  -e "SSH_KEY=$(cat ~/.ssh/container_key.pub)" \
  -e USER_PASSWORD="unsloth2024" \
  -p 8000:8000 -p 2222:22 \
  -v $(pwd)/work:/workspace/work \
  --gpus all \
  unsloth/unsloth
```

#### SSH-Schlüssel einrichten

Wenn Sie kein SSH-Schlüsselpaar haben:

```bash
# Neues Schlüsselpaar erzeugen
ssh-keygen -t rsa -b 4096 -f ~/.ssh/container_key

# Verwenden Sie den öffentlichen Schlüssel in docker run
-e "SSH_KEY=$(cat ~/.ssh/container_key.pub)"

# Verbinden Sie sich per SSH
ssh -i ~/.ssh/container_key -p 2222 unsloth@localhost
```

### ⚙️ Erweiterte Einstellungen

| Variable           | Beschreibung                                     | Standard  |
| ------------------ | ------------------------------------------------ | --------- |
| `JUPYTER_PASSWORD` | Jupyter-Lab-Passwort                             | `unsloth` |
| `JUPYTER_PORT`     | Jupyter-Lab-Port innerhalb des Containers        | `8888`    |
| `SSH_KEY`          | Öffentlicher SSH-Schlüssel zur Authentifizierung | `Keine`   |
| `USER_PASSWORD`    | Passwort für `unsloth` Benutzer (sudo)           | `unsloth` |

```bash
-p <host_port>:<container_port>
```

* Jupyter Lab: `-p 8000:8888`
* SSH-Zugriff: `-p 2222:22`

{% hint style="warning" %}
**Wichtig**: Verwenden Sie Volume-Mounts, um Ihre Arbeit zwischen Container-Starts zu erhalten.
{% endhint %}

```bash
-v <lokaler_Ordner>:<container_ordner>
```

```bash
docker run -d -e JUPYTER_PORT=8000 \
  -e JUPYTER_PASSWORD="mypassword" \
  -e "SSH_KEY=$(cat ~/.ssh/container_key.pub)" \
  -e USER_PASSWORD="unsloth2024" \
  -p 8000:8000 -p 2222:22 \
  -v $(pwd)/work:/workspace/work \
  --gpus all \
  unsloth/unsloth
```

### **🔒 Sicherheitshinweise**

* Der Container läuft standardmäßig als Nicht-Root- `unsloth` Benutzer
* Verwenden Sie `USER_PASSWORD` für sudo-Operationen innerhalb des Containers
* SSH-Zugriff erfordert öffentliche Schlüsselauthentifizierung


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://unsloth.ai/docs/de/blog/how-to-fine-tune-llms-with-unsloth-and-docker.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
