3
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

AWS EC2上にホスティングしているDifyをアプデートする手順

3
Posted at

1. 概要

AWS EC2 上で Docker Compose を用いて稼働している Dify アプリケーションを、安全にアップデート・運用するための手順をまとめている。

2. 構成前提

  • プラットフォーム: AWS EC2(Amazon Linux 2)
  • アプリ配置ディレクトリ: /home/ec2-user/dify/docker
  • Docker Compose バージョン: v2 系推奨
  • データ永続化: Docker Named Volume(例: dify_db_data, dify_weaviate_data など)
  • バックアップ手段: Volume アーカイブ(tar)または EBS スナップショット / AMI

3. 更新手順

  1. EC2 に SSH 接続

    ssh -i ~/.ssh/your-key.pem ec2-user@<EC2_PUBLIC_IP>
    
  2. リポジトリへ移動 & ソース取得

    cd dify/docker
    git pull origin <main | tag>
    
  3. コンテナ停止(Volume は温存)

    docker compose down       # --volumes は付けない!
    
  4. イメージ更新

    docker compose pull       # 最新イメージ取得
    
  5. コンテナ再起動

    docker compose up -d
    
  6. 動作確認

    docker compose ps         # ステータス確認
    docker compose logs -f <service>  # 必要に応じてログ監視
    

4. バックアップ & リストア

4.1 Volume バックアップ(ファイルレベル)

docker compose down
sudo tar -cvf dify-volumes-$(date +%Y%m%d).tar \
  /var/lib/docker/volumes/dify_*

または EC2 停止前に EBS スナップショット / AMI を取得。

4.2 リストア手順

  1. 対象 tar を展開 or スナップショット / AMI からリストア。
  2. docker compose up -d で再起動。

5. 設定ファイル同期

アップデート後は .env.example と既存 .env を比較し、新規変数を追記する。

diff -u .env.example .env

6. 障害時ロールバック

git checkout <previous-tag>   # 直前の安定版へ戻す
docker compose pull
docker compose up -d

なお、それでも復旧しない場合は Volume バックアップまたは AMI を戻す。

7. EC2 セッション終了

EC2 インスタンスから抜けたい場合は次のいずれかで OK。

exit      # 一般的
logout    # シェル依存
Ctrl + D  # EOF 送信
3
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?