> 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) はこれらの問題を回避できます。セットアップは不要です。イメージを pull して実行し、トレーニングを開始するだけです。

* **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" %}
これで、メインの Docker イメージを使用できます `unsloth/unsloth` Blackwell および 50 シリーズ GPU 向けに - 別のイメージは不要です。
{% 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 イメージです。For [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 by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

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

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

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.
