← Back to Dashboard
Verified Production Fix

[docker/cli] Unable to detect rollbacks during "docker stack deploy" in CI/CD

GH-docker/cli#6752 • Mar 07, 2026

### ROOT CAUSE The `docker stack deploy` command exits with code 0 even when a rollback occurs because Docker does not update the exit code to reflect deployment failures post-rollback. The current implementation only checks if the command ran without errors, not if the deployment was successful. ### CODE FIX To fix this, we can modify the CI/CD script to capture the output of `docker stack deploy` and check for specific indicators of a rollback. Here's an example using bash:
bash
# Run the deploy command and capture output and error streams
DEPLOY_OUTPUT=$(docker stack deploy --detach=false -c docker-compose.yml test-rollback 2>&1)

# Check if the output contains a rollback indication
if grep -q "rollback" <<< "$DEPLOY_OUTPUT"; then
    echo "Deployment failed with rollback"
    exit 1
fi

# If no rollback, exit with success
exit 0


**Explanation:**
- This script captures the output of `docker stack deploy`, including any error messages.
- It checks if the output contains the word "rollback", which indicates a deployment failure.
- If a rollback is detected, the script exits with code 1, signaling failure to the CI/CD pipeline.
- If no rollback occurs, it exits with code 0.

This solution ensures that the CI/CD pipeline correctly identifies deployment failures, allowing it to take appropriate corrective actions.

Deploy with DigitalOcean

Use this fix in production instantly. Claim your $200 developer credit.

Get Started →