> For the complete documentation index, see [llms.txt](https://docs.keeper.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.keeper.io/keeperpam/jp/secrets-manager/integrations/docker-writer-image.md).

# Docker Writerイメージ

## 概要

KSM用のDocker Writerイメージは、シークレットファイルをダウンロードし、シークレットを含むファイルを生成できるイメージです。

以下のコマンドでイメージを取得できます。

```
$ docker pull keeper/keeper-secrets-manager-writer
```

実行時は、パラメータを環境変数で渡します。

```
$ docker run \
    -v $PWD:/wd --workdir /wd \
    -e "KSM_CONFIG=BASE64 CONFIG" \
    -e "SECRETS=JfXpSQ2nZG6lkdl1rxB0dg/file/example.crt > file:example.crt"
    keeper/keeper-secrets-manager-writer
```

{% hint style="info" %}
このライターイメージは、ボルトからファイルをコピーし、シークレットを含むファイルを作成するために使います。ディスクへの書き込みは漏洩リスクを伴うため、代替手段として[keeper/keeper-secrets-manager-cli](/keeperpam/jp/secrets-manager/secrets-manager-command-line-interface/docker-container.md)イメージの `exec` コマンドの利用を検討してください。
{% endhint %}

## パラメータ

パラメータは環境変数としてコンテナに渡します。

| パラメータ               | 説明                                                    |
| ------------------- | ----------------------------------------------------- |
| `KSM_CONFIG`        | Base64でエンコードされた設定ファイル                                 |
| `SECRETS`           | Keeper表記法と代入先の改行区切りのリスト                               |
| `SECRETS_FILE`      | ファイル以外のシークレットを書き込むファイル名                               |
| `SECRETS_FILE_TYPE` | シークレットファイルの形式。有効な形式はexport、setenv、set、JSON。デフォルトはJSON |
| `CLEANUP_FILE`      | 設定時、作成ファイルを削除用シェルスクリプトに追加。実行で一括削除可能                   |

## シークレットリスト

`SECRETS` は、Keeper表記法と代入先のリストです。値は改行で区切られています。以下に例を示します。

```
fXpSQ2nZG6lkdl1rxB0dg/file/example.crt > file:example.crt
cl9a9k0DWP-Iy227rBo5gQ/field/login > MY_LOGIN
gpsBL343CVYMFgOKZ-L2hQ/custom_field/Ip Address > IP_ADDR
```

各行は「[Keeper表記法](/keeperpam/jp/secrets-manager/about/keeper-notation.md) > 代入先」です。代入先には、環境変数/JSONキーまたはファイルのパスと名前を指定できます。ファイルの場合、パスの先頭に `file:` を付けます。文字列エンコーディングが不明なため、バイナリデータを環境変数に格納しないことをお勧めします。

### シークレットファイルの形式

シークレットファイルには、環境変数 `SECRETS` の値が格納されます。ファイル形式は `SECRETS_FILE_TYPE` の値に基づいています。タイプには以下の値を指定できます。

* **json:** JSON形式で格納される値
* **export:** BASHシェルで一般的に使用されるエクスポートコマンドとして格納される値
* **setenv:** Cシェルで一般的に使用されるsetenvコマンドとして格納される値
* **set:** Cシェルで一般的に使用されるsetコマンドとして格納される値

シェルに関連するタイプを読み込んで、シークレットを環境変数に格納できます。

## 例

KSM用のDocker Writerイメージは、多くのアプリケーションで使用できます。いくつかの例を紹介します。

### Kubernetes

ライターイメージは、[Initコンテナ](https://kubernetes.io/docs/concepts/workloads/pods/init-containers/)で使用するのが最適です。

```
 initContainers:
    - name: my_app
      image: keeper/keeper-secrets-manager-writer:latest
      env:
        - name: SECRETS
          value: |
            qCAw9dMQgr3Hs7EdfFpfkA/field/password > my_password
            qCAw9dMQgr3Hs7EdfFpfkA/file/exmaple.crt > file:/etc/keys/example.crt
            qCAw9dMQgr3Hs7EdfFpfkA/file/exmaple.key > file:/etc/keys/example.key
```

このコンテナでは、ライターイメージでファイルを保存し、メインコンテナがアクセスできるシークレットファイルを作成します。ボリュームをマウントしてファイルを書き込み、メインコンテナに同じボリュームをマウントします。PodのemptyDirが適しています。

### Docker Compose

**main**サービスで `depends_on` オプションを使用すると、KSM用のDocker Writerイメージを初期化サービスで使用できます。以下の例では、Docker Writerがボルトからシークレットを取得し、ボリュームマウントでmainイメージと共有します。

```
---
version: "2"
services:
  init:
    image: keeper/keeper-secrets-manager-writer:latest
    environment:
      KSM_CONFIG: R2VwWTVDS ... dmVyUHVibGljS2V5SWQiOiAiMTAiCn0=
      SECRETS: |
        qCAw9dMQgr3Hs7EdfFpfkA/field/password > file:/etc/keys/global.pass
        qCAw9dMQgr3Hs7EdfFpfkA/file/myserver.crt > file:/etc/keys/myserver.crt
        qCAw9dMQgr3Hs7EdfFpfkA/file/myserver.key > file:/etc/keys/myserver.key
    volumes:
      - keys-volume:/etc/keys
  main:
    image: nginx
    restart: always
    volumes:
     - ./config:/etc/nginx/conf.d
     - keys-volume:/etc/keys
    ports:
     - "80:80"
     - "443:443"
    environment:
     - NGINX_HOST=example.com
    depends_on:
      init:
        condition: service_completed_successfully
volumes:
  keys-volume:
```

通常、サービスは同時に開始されますが、`depends_on` オプションで開始順序を制御できます。上記では、**main**サービスが**init**サービスに依存します。

**init**サービスが起動し、ファイルを取得してkeys-volumeに保存した後、終了します。`service_completed_successfully` 条件により、**init**サービスが正常終了してから**main**サービスが開始されます。**main**サービスは `keys-volume` をマウントし、格納された鍵を使用します。

### Dockerコマンドライン

ライターイメージは `docker run` でコマンドラインから実行できます。

```
docker run \
    -v $PWD:/wd --workdir /wd \
    -e "KSM_CONIFG=BASE64 CONFIG" \
    -e "SECRETS=JfXpSQ2nZG6lkdl1rxB0dg/file/example.crt > file:example.crt"
    keeper/keeper-secrets-manager-writer
```

`SECRETS` に複数のシークレットが設定されている場合、改行文字（\n）を表記するのは困難です。解決策は、`--env,-e` 値を $" で囲むことです。以下に例を示します。

```
-e $'SECRETS=V8lFbio0Bs0LuvaSD5DDHA/file/IMG_0036.png > file:my.png\nIumwT1QYRr8TTCtY8rqzhw/custom_field/S3_BUCKET > s3'
```

**file:my.png**と以降のレコードUIDの間に「\n」があります。値全体を$''で囲まない場合、my.pngファイル名に改行コードと以降のレコードUIDが含まれてしまいます。


---

# 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:

```
GET https://docs.keeper.io/keeperpam/jp/secrets-manager/integrations/docker-writer-image.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.
