---
name: docker-build-push
description: Build Docker images and push to Docker Hub for Coolify deployment. Use when the user needs to (1) build a Docker image locally, (2) push an image to Docker Hub, (3) deploy to Coolify via Docker image, or (4) set up CI/CD for Docker-based deployments with Gitea Actions.
---

# Docker Build and Push

Build Docker images locally and push to Docker Hub for Coolify deployment.

## Prerequisites

1. Docker installed and running
2. Docker Hub account
3. Logged in to Docker Hub: `docker login`

## Build and Push Workflow

### 1. Build the Image

```bash
docker build -t DOCKERHUB_USERNAME/IMAGE_NAME:latest .
```

Optional version tag:

```bash
docker build -t DOCKERHUB_USERNAME/IMAGE_NAME:v1.0.0 .
```

### 2. Test Locally (Optional)

```bash
docker run -p 3000:3000 DOCKERHUB_USERNAME/IMAGE_NAME:latest
```

### 3. Push to Docker Hub

```bash
docker push DOCKERHUB_USERNAME/IMAGE_NAME:latest
```

## Coolify Deployment

In Coolify dashboard:

1. Create/edit service → Select **Docker Image** as source
2. Enter image: `DOCKERHUB_USERNAME/IMAGE_NAME:latest`
3. Configure environment variables
4. Deploy

## Automated Deployment with Gitea Actions

Create `.gitea/workflows/deploy.yaml`:

```yaml
name: Deploy to Coolify

on:
  push:
    branches:
      - main

jobs:
  deploy:
    runs-on: ubuntu-latest
    steps:
      - name: Trigger Coolify Deployment
        run: |
          curl -X POST "${{ secrets.COOLIFY_WEBHOOK_URL }}"
```

### Setup:

1. **Get Coolify Webhook URL**: Service settings → Webhooks → Copy URL
2. **Add to Gitea Secrets**: Settings → Secrets → Add `COOLIFY_WEBHOOK_URL`

### Full Workflow:

1. Build and push locally
2. Push code to Gitea (triggers workflow)
3. Gitea notifies Coolify
4. Coolify pulls latest image and redeploys
