Fix Docker Compose cache issue with proper cleanup

- Use docker-compose down to clear old service definitions
- Use docker system prune -f to remove cached metadata
- Verify new compose file is deployed correctly
- Force rebuild with --build flag
- This ensures new nginx-only config is used instead of cached old stack

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
happybell80 2025-07-07 23:50:39 +09:00
parent f5253ac3e5
commit c44bc1b4b4

View File

@ -56,32 +56,33 @@ jobs:
ssh -p ${{ secrets.NAS_PORT }} admin@${{ secrets.NAS_HOST }} \
"ls -la /var/run/docker.sock && id"
- name: Clean up old containers
- name: Deploy with fresh Docker Compose
run: |
ssh -p ${{ secrets.NAS_PORT }} admin@${{ secrets.NAS_HOST }} << 'EOF'
cd /volume1/homes/admin/nginx-infra
# Stop and remove old containers
# 1) Tear down everything so old services & networks go away
if ! docker ps > /dev/null 2>&1; then
echo "Using sudo for docker commands..."
sudo docker-compose down --remove-orphans 2>/dev/null || true
sudo docker-compose down 2>/dev/null || true
# 2) Prune out any stopped containers, unused networks, images, and build cache
sudo docker system prune -f
else
echo "Direct docker access available..."
docker-compose down --remove-orphans 2>/dev/null || true
docker-compose down 2>/dev/null || true
# 2) Prune out any stopped containers, unused networks, images, and build cache
docker system prune -f
fi
EOF
- name: Remote docker-compose up
run: |
ssh -p ${{ secrets.NAS_PORT }} admin@${{ secrets.NAS_HOST }} << 'EOF'
cd /volume1/homes/admin/nginx-infra
# Start new containers
# 3) Double-check you're seeing the new compose file
echo "---- current compose file ----"
cat docker-compose.yml
echo "------------------------------"
# 4) Rebuild from that file and bring up only your nginx service
if ! docker ps > /dev/null 2>&1; then
echo "Using sudo for docker commands..."
sudo docker-compose up -d --build
else
echo "Direct docker access available..."
docker-compose up -d --build
fi
EOF