> ## Documentation Index
> Fetch the complete documentation index at: https://docs.dcdeploy.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Rebuild & Deploy

> The **Rebuild & Deploy** feature in DCDeploy forces a fresh build of your service and then redeploys it. This is different from a normal **Redeploy**, which may reuse the latest built image. With **Rebuild & Deploy**, the entire Docker image is rebuilt from scratch and then rolled out.

## When to use Rebuild & Deploy

* **Dockerfile changes** – When you’ve updated the `Dockerfile` or build context.
* **Dependencies update** – If you changed `package.json`, `requirements.txt`, or other dependency files.
* **Build configuration changes** – Updating `context`, `dockerfilePath`, or `autoBuild` in `DCDeploy.yml`.
* **Corrupted image fixes** – Forcing a clean rebuild ensures the latest state is deployed.

## How Rebuild & Deploy Works

1. **Fresh Build**
   * DCDeploy ignores cached layers.
   * A new Docker image is built from your repository or build context.

2. **Deploy Rollout**
   * The new image is deployed to your service.
   * If **zero downtime deployment** is enabled, old containers are kept alive until the new ones pass health checks.

## Rebuild & Deploy via Dashboard

1. Open the **DCDeploy dashboard**.
2. Navigate to your service.
3. Click **Rebuild & Deploy**.
4. Confirm the rebuild trigger.
5. Watch build and deployment logs in real-time.

### Auto Rebuild on Commit

If you set `autoBuild:` true in your DCDeploy.yml, DCDeploy automatically triggers a Rebuild & Deploy whenever you push new commits to the specified branch.

Example:

```yaml theme={null}
services:
  my-app:
    build:
      context: ./
      dockerfilePath: ./Dockerfile
      repo: my-org/my-repo
      ref: main
      refType: branch
      autoBuild: true
```

* Every commit to main will rebuild and deploy the service automatically.
* Ensures your production always runs the latest code.
* Works with both public and private repositories.

### Key Difference: Redeploy vs Rebuild & Deploy

| Feature            | Redeploy                 | Rebuild & Deploy                      |
| ------------------ | ------------------------ | ------------------------------------- |
| Uses cached image? | Yes                      | No (fresh build)                      |
| Speed              | Faster                   | Slower (full build)                   |
| Use case           | Code/config changes only | Dockerfile/dependencies/build changes |

### Best Practices

* Use Redeploy for small code/config changes.
* Use Rebuild & Deploy when build environment changes are required.
* Test in staging before running on production.
* Enable zero downtime to avoid interruptions during rebuilds.
* Prefer autoBuild: true for continuous integration workflows.

By using Rebuild & Deploy, you ensure your service always runs on the freshest possible build, eliminating risks from outdated or cached images.
