# Comment affiner des LLM avec Unsloth et Docker

La formation locale peut être complexe en raison d'un enfer de dépendances ou d'environnements cassés. L' [image Docker](https://hub.docker.com/r/unsloth/unsloth) peut contourner ces problèmes. Aucune configuration n'est nécessaire : récupérez et exécutez l'image et commencez la formation.

* **Image Docker officielle d'Unsloth :** [**`unsloth/unsloth`**](https://hub.docker.com/r/unsloth/unsloth)

**Pourquoi utiliser Unsloth & Docker ?**

L'image Docker d'Unsloth est stable, à jour et fonctionne dans [configurations prises en charge](/docs/fr/commencer/fine-tuning-for-beginners/unsloth-requirements.md#system-requirements) comme Windows.

* Des dépendances entièrement contenues gardent votre système propre. S'exécute en toute sécurité sans root.
* Utilisez localement ou sur n'importe quelle plateforme avec des notebooks préinstallés.

{% hint style="success" %}
Vous pouvez désormais utiliser notre image Docker principale `unsloth/unsloth` pour les GPU Blackwell et série 50 - aucune image séparée nécessaire.
{% endhint %}

### ⚡ Tutoriel étape par étape

{% stepper %}
{% step %}
**Installez Docker et NVIDIA Container Toolkit.**

Installez Docker via [Linux](https://docs.docker.com/engine/install/) ou [Bureau](https://docs.docker.com/desktop/) (autre).\
Puis installez [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/2da224e286b3992f4342c5066823f63e5cf74620" alt=""><figcaption></figcaption></figure>
{% endstep %}

{% step %}
**Exécutez le conteneur.**

[**`unsloth/unsloth`**](https://hub.docker.com/r/unsloth/unsloth) est la seule image Docker d'Unsloth. Pour [Blackwell](/docs/fr/blog/fine-tuning-llms-with-blackwell-rtx-50-series-and-unsloth.md) et les GPU série 50, utilisez cette même image - aucune image séparée nécessaire. Si vous utilisez DGX Spark, vous devrez suivre notre [guide DGX](/docs/fr/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/19d60b34f09d2d4cfbae1491151afe23f91dd967" alt=""><figcaption></figcaption></figure>
{% endstep %}

{% step %}
**Accéder à Jupyter Lab**

Allez à [http://localhost:8888](http://localhost:8888/) et ouvrez Unsloth.

<figure><img src="/files/29f53461c91132bd694568a797cdd4b7c4e3d44c" alt="" width="563"><figcaption></figcaption></figure>

Accédez aux `unsloth-notebooks` onglets pour voir les notebooks Unsloth.

<div><figure><img src="/files/46c8f089c29870b2fa229972a07bc83cb09670f5" alt=""><figcaption></figcaption></figure> <figure><img src="/files/6feac03e747120bacbde045bca66561d1c20bbfc" alt=""><figcaption></figcaption></figure></div>
{% endstep %}

{% step %}
**Commencez la formation avec Unsloth**

Si vous êtes nouveau, suivez notre [Guide de fine-tuning](/docs/fr/commencer/fine-tuning-llms-guide.md), [Guide RL](/docs/fr/commencer/reinforcement-learning-rl-guide.md) ou simplement enregistrez/copiez n'importe lequel de nos [notebooks](/docs/fr/commencer/unsloth-notebooks.md).

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

#### 📂 Structure du conteneur

* `/workspace/work/` — Votre répertoire de travail monté
* `/workspace/unsloth-notebooks/` — Exemples de notebooks de fine-tuning
* `/home/unsloth/` — Répertoire personnel de l'utilisateur

### 📖 Exemple d'utilisation

#### Exemple complet

```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
```

#### Configuration de la clé SSH

Si vous n'avez pas de paire de clés SSH :

```bash
# Générer une nouvelle paire de clés
ssh-keygen -t rsa -b 4096 -f ~/.ssh/container_key

# Utilisez la clé publique dans docker run
-e "SSH_KEY=$(cat ~/.ssh/container_key.pub)"

# Connectez-vous via SSH
ssh -i ~/.ssh/container_key -p 2222 unsloth@localhost
```

### ⚙️ Paramètres avancés

| Variable           | Description                                      | Par défaut |
| ------------------ | ------------------------------------------------ | ---------- |
| `JUPYTER_PASSWORD` | Mot de passe Jupyter Lab                         | `unsloth`  |
| `JUPYTER_PORT`     | Port de Jupyter Lab à l'intérieur du conteneur   | `8888`     |
| `SSH_KEY`          | Clé publique SSH pour l'authentification         | `Aucun`    |
| `USER_PASSWORD`    | Mot de passe pour `unsloth` l'utilisateur (sudo) | `unsloth`  |

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

* Jupyter Lab : `-p 8000:8888`
* Accès SSH : `-p 2222:22`

{% hint style="warning" %}
**Important** : Utilisez des montages de volumes pour préserver votre travail entre les exécutions du conteneur.
{% endhint %}

```bash
-v <dossier_local>:<dossier_conteneur>
```

```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
```

### **🔒 Notes de sécurité**

* Le conteneur s'exécute par défaut en tant qu'utilisateur non-root `unsloth` par défaut
* Utilisez `USER_PASSWORD` pour les opérations sudo à l'intérieur du conteneur
* L'accès SSH nécessite l'authentification par clé publique


---

# 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/fr/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.
