> For the complete documentation index, see [llms.txt](https://docs.hivel.ai/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.hivel.ai/self-managed-hivel-deployment/virtual-private-cloud/aws/hivel-on-premises-deployment-guide-aws/deployment-methods/method-2-deployment-using-docker-compose.md).

# Method 2: Deployment Using Docker Compose

On-prem Deployment Guide (AWS)

**Goal:** Deploy Hivel VM services using Docker Compose with manual orchestration.

### **Prerequisites:**

* Database Migration completed successfully
* `.env` file configured with application user credentials (DB\_USER and DB\_PASSWORD)
* Docker and Docker Compose installed on VM
* AWS ECR access configured (IAM role or AWS CLI credentials)
* Advanced Docker and Docker Compose knowledge

### Step 1: Authenticate with AWS ECR

**Application/System:** EC2 VM (AWS CLI and Docker)

**Goal:** Log Docker in to the AWS ECR registry so images can be pulled.

**For Hivel's ECR:**

```
# Authenticate with ECR
aws ecr get-login-password --region ap-south-1 | \
  docker login --username AWS --password-stdin \
  730335373269.dkr.ecr.ap-south-1.amazonaws.com

```

For your own ECR:

```
aws ecr get-login-password --region YOUR_REGION | \
  docker login --username AWS --password-stdin \
  YOUR_ACCOUNT.dkr.ecr.YOUR_REGION.amazonaws.com
```

**Expected result:** Output shows `Login Succeeded`.

**If it fails:** Verify AWS credentials are configured and have ECR permissions.

### Step 2: Create Docker Network

**Application/System:** EC2 VM (Docker)

**Goal:** Create a shared network for all services to communicate.

```
docker network create microservices_network
```

**Expected result:** Command prints a network ID with no errors.

### Step 3: Deploy VM Services

**Application/System:** EC2 VM (Docker Compose)

**Goal:** Pull images and start all services.

**On your EC2 VM, run:**

```
cd /opt/hivel-onprem/services/vm

# Pull all images
docker-compose --env-file ../../config/.env pull

# Deploy all services
docker-compose --env-file ../../config/.env up -d

# Or deploy specific service
docker-compose --env-file ../../config/.env up -d auth-svc
```

Wait 2-5 minutes for all services to start.

#### Docker Compose Management Commands

**Use these commands to manage services after deployment:**

```
# View running services
docker-compose ps

# View logs
docker-compose logs -f
docker-compose logs -f <service-name>

# Stop services
docker-compose stop

# Start services
docker-compose start

# Restart services
docker-compose restart

# Remove services
docker-compose down

# Update services
docker-compose pull
docker-compose up -d

```

#### Important Notes

* All commands must be run from `/opt/hivel-onprem/services/vm` directory
* Always use `--env-file ../../config/.env` to ensure services read correct configuration
* Services communicate via the `microservices_network` created in Step 2
* Logs are displayed live with `docker-compose logs -f`; use `Ctrl+C` to exit
* Do not manually manage the Docker network or service ordering; Docker Compose handles this
* Keep all services on the same Docker network for communication

***

#### Next Steps

After successful deployment:

1. Verify all services are running: `docker-compose ps`
2. Check logs for any errors: `docker-compose logs`
3. Access the Hivel application at the configured frontend URL
4. Proceed to [Log Rotation Setup](https://docs.hivel.ai/self-managed-hivel-deployment/virtual-private-cloud/aws/hivel-on-premises-deployment-guide-aws/log-rotation-setup)

***

#### Quick Troubleshooting

* **Image pull fails:** Verify ECR authentication succeeded (Login Succeeded)
* **Services fail to start:** Check `.env` file has correct database credentials and RDS is reachable
* **Services can't communicate:** Verify all services are on `microservices_network` with `docker network inspect microservices_network`
* **Permission denied errors:** Ensure user running Docker Compose has Docker permissions

See [Troubleshooting](https://docs.hivel.ai/self-managed-hivel-deployment/virtual-private-cloud/aws/hivel-on-premises-deployment-guide-aws/troubleshooting) for detailed solutions.

{% columns %}
{% column %} <a href="/self-managed-hivel-deployment/virtual-private-cloud/aws/hivel-on-premises-deployment-guide-aws/deployment-methods/method-1-using-deploy.sh-script-recommended.md" class="button primary" data-icon="backward">Back to Method 1: Deploy.sh</a>
{% endcolumn %}

{% column %}

{% endcolumn %}

{% column %} <a href="/self-managed-hivel-deployment/virtual-private-cloud/aws/hivel-on-premises-deployment-guide-aws/log-rotation-setup.md" class="button primary" data-icon="forward">Log Rotation Setup</a>
{% endcolumn %}
{% endcolumns %}
