> 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/jp/burogu/how-to-fine-tune-llms-with-unsloth-and-docker.md).

# Unsloth と Docker で LLM をファインチューニングする方法

Unsloth の Docker イメージを使って、LLM をファインチューニングしたり強化学習 (RL) を行う方法を学びます。

ローカルでのトレーニングは、依存関係の問題や環境の破損により複雑になることがあります。Unsloth の [Docker イメージ](https://hub.docker.com/r/unsloth/unsloth) なら、これらの問題を回避できます。セットアップは不要です。イメージをプルして実行し、トレーニングを開始してください。

* **Unsloth 公式 Docker イメージ：** [**`unsloth/unsloth`**](https://hub.docker.com/r/unsloth/unsloth)

**Unsloth と Docker を使う理由**

Unsloth の Docker イメージは安定しており、最新の状態に保たれ、 [サポートされている環境](/docs/jp/meru/fine-tuning-for-beginners/unsloth-requirements.md#system-requirements) （Windows など）で動作します。

* 依存関係が完全にコンテナ化されるため、システムをクリーンに保てます。root なしで安全に実行できます。
* ローカルでも、ノートブックがあらかじめインストールされた任意のプラットフォームでも使用できます。

{% hint style="success" %}
Blackwell および 50 シリーズ GPU 向けにも、メインの Docker イメージを使用できるようになりました `unsloth/unsloth` — 別のイメージは不要です。
{% endhint %}

### ⚡ ステップバイステップチュートリアル

{% stepper %}
{% step %}
**Docker と NVIDIA Container Toolkit をインストールします。**

Docker を以下からインストールします： [Linux](https://docs.docker.com/engine/install/) または [Desktop](https://docs.docker.com/desktop/) （その他）。\
次に、 [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://735611837-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 %}
**コンテナを実行します。**

[**`unsloth/unsloth`**](https://hub.docker.com/r/unsloth/unsloth) は Unsloth の唯一の Docker イメージです。 [Blackwell](/docs/jp/burogu/fine-tuning-llms-with-blackwell-rtx-50-series-and-unsloth.md) および 50 シリーズ GPU では、この同じイメージを使用してください。別のイメージは不要です。DGX Spark を使用する場合は、 [DGX ガイド](/docs/jp/burogu/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://735611837-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 %}
**Jupyter Lab にアクセス**

次へ移動： [http://localhost:8888](http://localhost:8888/) そして Unsloth を開きます。

<figure><img src="https://735611837-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>

次にアクセスします： `unsloth-notebooks` タブを開くと、Unsloth のノートブックを確認できます。

<div><figure><img src="https://735611837-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://735611837-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 %}
**Unsloth でトレーニングを開始**

初めての場合は、ステップバイステップの [ファインチューニングガイド](/docs/jp/meru/fine-tuning-llms-guide.md), [RL ガイド](/docs/jp/meru/reinforcement-learning-rl-guide.md) に従うか、あらかじめ用意された [ノートブック](/docs/jp/meru/unsloth-notebooks.md).

<figure><img src="https://735611837-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 %}

#### 📂 コンテナ構造

* `/workspace/work/` — マウントされた作業ディレクトリ
* `/workspace/unsloth-notebooks/` — ファインチューニング用ノートブックの例
* `/home/unsloth/` — ユーザーのホームディレクトリ

### 📖 使用例

#### 完全な例

```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 キーの設定

SSH キーペアがない場合：

```bash
# 新しいキーペアを生成
ssh-keygen -t rsa -b 4096 -f ~/.ssh/container_key

# docker run で公開鍵を使用
-e "SSH_KEY=$(cat ~/.ssh/container_key.pub)"

# SSH 経由で接続
ssh -i ~/.ssh/container_key -p 2222 unsloth@localhost
```

### ⚙️ 詳細設定

| 変数                 | 説明                          | デフォルト     |
| ------------------ | --------------------------- | --------- |
| `JUPYTER_PASSWORD` | Jupyter Lab のパスワード          | `unsloth` |
| `JUPYTER_PORT`     | コンテナ内の Jupyter Lab ポート      | `8888`    |
| `SSH_KEY`          | 認証用 SSH 公開鍵                 | `なし`      |
| `USER_PASSWORD`    | のパスワード `unsloth` ユーザー（sudo） | `unsloth` |

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

* Jupyter Lab： `-p 8000:8888`
* SSH アクセス： `-p 2222:22`

{% hint style="warning" %}
**重要**：コンテナの実行間で作業内容を保持するには、ボリュームマウントを使用してください。
{% 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
```

### **🔒 セキュリティに関する注意**

* コンテナは非 root `unsloth` ユーザーとしてデフォルトで実行されます
* 使用してください `USER_PASSWORD` コンテナ内で sudo 操作を行うには
* SSH アクセスには公開鍵認証が必要です


---

# 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/jp/burogu/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.
