fix: resolve container name conflict in rebuild CD step
Some checks failed
CD Pipeline / deploy (push) Failing after 45s

'docker compose up --force-recreate' fails when the existing container
was started by a different compose invocation, leaving a stale container
with the same name. Error: 'container name already in use'.

Fix: explicitly stop + rm the two containers before compose build & up.
Using 2>/dev/null to ignore errors if containers are already stopped.
Removed --force-recreate (no longer needed after explicit rm).
This commit is contained in:
ogt
2026-04-20 06:46:04 +08:00
parent 456c031955
commit 2ffbe06eab

View File

@@ -152,9 +152,14 @@ jobs:
--exclude='.env' \
--exclude='*.db' \
./ ollama@192.168.0.188:/home/ollama/momo-pro/
# 重建並重啟(兩容器共用同一 imagetelegram-bot 已於 2026-04-20 移除
# 重建並重啟(先強制移除舊容器,避免 container name conflict
ssh -i ~/.ssh/id_deploy -o StrictHostKeyChecking=no ollama@192.168.0.188 \
"cd /home/ollama/momo-pro && docker compose build momo-app && docker compose up -d --no-deps --force-recreate momo-app scheduler && echo '✅ Image 重建完成'"
"cd /home/ollama/momo-pro && \
docker stop momo-pro-system momo-scheduler 2>/dev/null; \
docker rm momo-pro-system momo-scheduler 2>/dev/null; \
docker compose build momo-app && \
docker compose up -d --no-deps momo-app scheduler && \
echo '✅ Image 重建完成'"
# ── 健康檢查(最多重試 5 次,每次間隔 10s ───────────────────────────
- name: 健康檢查