> For the complete documentation index, see [llms.txt](https://unsloth.ai/docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://unsloth.ai/docs/fr/blog/how-to-fine-tune-llms-with-unsloth-and-docker.md).

# Comment affiner des LLM avec Unsloth et Docker

Découvrez comment affiner des LLM ou faire de l’apprentissage par renforcement (RL) avec l’image Docker d’Unsloth.

L'entraînement local peut être complexe à cause de l'enfer des dépendances ou d'environnements cassés. Le [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, puis commencez l'entraînement.

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

**Pourquoi utiliser Unsloth et Docker ?**

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

* Les dépendances entièrement contenues gardent votre système propre. S'exécute en toute sécurité sans root.
* Utilisez-le 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 de la série 50 - pas besoin d'image séparée.
{% endhint %}

### ⚡ Tutoriel pas à pas

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

Installez Docker via [Linux](https://docs.docker.com/engine/install/) ou [Desktop](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="https://550366147-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FxhOjnexMCB3dmuQFQ2Zq%2Fuploads%2Fgit-blob-41cae231ed4761f844ce9836e03b17aabd7c803c%2Fnvidia%20toolkit.png?alt=media" 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 de la série 50, utilisez cette même image - aucune image séparée n'est 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="https://550366147-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FxhOjnexMCB3dmuQFQ2Zq%2Fuploads%2Fgit-blob-2b50d78c5d54eaf189c0a40d46c405585ea23082%2Fdocker%20run.png?alt=media" alt=""><figcaption></figcaption></figure>
{% endstep %}

{% step %}
**Accéder à JupyterLab**

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

<figure><img src="https://550366147-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FxhOjnexMCB3dmuQFQ2Zq%2Fuploads%2Fgit-blob-828df0a668fd94025c1193c24a7f09c1d58dcbd8%2Fjupyter.png?alt=media" alt="" width="563"><figcaption></figcaption></figure>

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

<div><figure><img src="https://550366147-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FxhOjnexMCB3dmuQFQ2Zq%2Fuploads%2Fgit-blob-e7a3f620a3ec5bff335632ff9b0cb422f76528a1%2FScreenshot_from_2025-09-30_21-38-15.png?alt=media" alt=""><figcaption></figcaption></figure> <figure><img src="https://550366147-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FxhOjnexMCB3dmuQFQ2Zq%2Fuploads%2Fgit-blob-531882c33eb96dec24e2d7673471d6a3928a3951%2FScreenshot_from_2025-09-30_21-39-41.png?alt=media" alt=""><figcaption></figcaption></figure></div>
{% endstep %}

{% step %}
**Commencez l'entraînement avec Unsloth**

Si vous débutez, suivez notre guide [Guide de fine-tuning](/docs/fr/commencer/fine-tuning-llms-guide.md), [Guide RL](/docs/fr/commencer/reinforcement-learning-rl-guide.md) ou sauvegardez/copiez simplement l'un de nos [notebooks](/docs/fr/commencer/unsloth-notebooks.md).

<figure><img src="https://550366147-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FxhOjnexMCB3dmuQFQ2Zq%2Fuploads%2Fgit-blob-665f900b008991ddcd8fdabb773b292de3c41e72%2FScreenshot_from_2025-09-30_21-40-29.png?alt=media" alt=""><figcaption></figcaption></figure>
{% endstep %}
{% endstepper %}

#### 📂 Structure du conteneur

* `/workspace/work/` — Votre répertoire de travail monté
* `/workspace/unsloth-notebooks/` — Notebooks d'exemple pour le 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

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

# Se connecter 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 de JupyterLab                     | `unsloth`  |
| `JUPYTER_PORT`     | Port JupyterLab à l'intérieur du conteneur     | `8888`     |
| `SSH_KEY`          | Clé publique SSH pour l'authentification       | `Aucun`    |
| `USER_PASSWORD`    | Mot de passe pour `unsloth` utilisateur (sudo) | `unsloth`  |

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

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

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

```bash
-v <local_folder>:<container_folder>
```

```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 sans privilèges root `unsloth` utilisateur par défaut
* Utilisez `USER_PASSWORD` pour les opérations sudo à l'intérieur du conteneur
* L'accès SSH nécessite une authentification par clé publique


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## 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, and the optional `goal` query parameter:

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

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
