# How to Deploy a Custom Docker Application from a Git Repository with xCloud

> Deploy a Docker Compose app from a Git repository with xCloud: pick the repository, scan its ports, set your .env, and go live on an NGINX server.

You can deploy any app that ships a Docker Compose file straight from its Git repository. xCloud reads the compose file, finds the ports your app publishes, puts your domain in front of the right one, and runs the containers on your server.

This guide walks you through the whole process, from creating or picking an NGINX server to deploying your application and going live. For server sizes and prices, see the [Docker container hosting](/docker-hosting/) page.

## Step 1: Create or pick an NGINX server

You need an NGINX server; OpenLiteSpeed servers cannot run Docker. If you already have one, go to Step 2. To create one, click **New Server** on the dashboard and choose your provider. You can use an [xCloud Managed Server](/managed-hosting/) or connect your [own server](/self-managed-hosting/).

![The New Server button on the xCloud dashboard](/_landing/docs/how-to-deploy-custom-docker-application-from-git-repository-image-100.png)

Enter the **Server Name**, and optionally pick an **App Type** and **Tags** that help you find the server later. Under **Choose Web Server**, select **NGINX**. Docker is not a separate choice.

![NGINX selected under Choose Web Server in the xCloud server form](/_landing/docs/how-to-deploy-custom-docker-application-from-git-repository-image-101.png)

Fill in the rest of the form for your provider (server size, or IP address and SSH details for your own server), then create the server. A new server can take a few minutes to become ready.

xCloud installs Docker during your first container deploy, so you can skip this. To have Docker ready before that, open the server, go to **Management** → **Settings**, click **Install a Service** at the top of **Server Utilities**, then click **Install** next to **Docker**. See [Enable Docker on an NGINX server](/docs/enable-docker-on-an-nginx-server-in-xcloud/) for details.

![The Install a Service button in Server Utilities on the server's Management → Settings page](/_landing/docs/how-to-deploy-custom-docker-application-from-git-repository-image-102.png)

## Step 2: Start a new site on your server

Open your server from **Servers** and click **New Site** at the top right. The **Add Your New Site Into** panel opens with your server's name.

![The New Site button on the server page and the Add Your New Site Into panel in xCloud](/_landing/docs/how-to-deploy-custom-docker-application-from-git-repository-image-103.png)

## Step 3: Open Deploy via Git and pick your repository

Click the **Deploy via Git** tab. Under **Deploy Any App From Git**, pick where your code lives:

- **Public Repository**: paste the repository URL (for example `https://github.com/your-account/your-app`) into the search box and press Enter.
- **Private Repository**: choose a connected Git account and search for the repository. No account connected yet? Click **Connect a Git provider**, or paste the repository's SSH URL (`git@…`) and xCloud shows a deploy key to add to the repository.

![The Deploy via Git tab and the repository search box in xCloud](/_landing/docs/how-to-deploy-custom-docker-application-from-git-repository-image-95.png)

xCloud checks the repository and shows it under **Paste your repository URL**. To use a different repository, click **Change Repository**.

## Step 4: Choose Docker container

Above the repository, click **Docker container**. xCloud may suggest **Native app** for some repositories; **Docker container** runs your app from its compose file instead.

![The Docker container option above the selected repository in xCloud](/_landing/docs/how-to-deploy-custom-docker-application-from-git-repository-image-96.png)

If Docker is not on the server yet, a note says it will be installed automatically during the first deployment. You don't need to do anything.

## Step 5: Set the branch to deploy

Under **Configuration**, check the **Branch** field. This is the branch xCloud clones and deploys, and you can change it here without picking the repository again.

![The Branch field under Configuration, filled with the repository's default branch](/_landing/docs/how-to-deploy-custom-docker-application-from-git-repository-image-105.png)

What you see in the field depends on how you picked the repository:

- **xCloud found the repository's default branch**: the field is already filled, for example with `main`. Keep it, or type another branch name.
- **The field is empty**: type the branch you want to deploy. The field shows **Enter the branch to deploy** until you do.
- **A private repository pasted as an SSH URL (`git@…`)**: after you add the deploy key and xCloud verifies it, the field fills in with the repository's default branch if you left it empty.

Each branch can hold a different compose file, Dockerfile or ports, so xCloud checks the branch you type. A moment after you stop typing, it scans the compose file, the Dockerfile and the ports again on that branch. If you added a deploy key, xCloud also checks again that the key can reach the repository, which confirms the branch exists.

**Deploy** stays locked until the field has a branch. While it is empty, the message **Enter the branch to deploy.** shows next to the button.

![The Enter the branch to deploy message next to the locked Deploy button](/_landing/docs/how-to-deploy-custom-docker-application-from-git-repository-image-106.png)

## Step 6: Set the compose file and scan its ports

If your repository also has a Dockerfile, xCloud shows **Deploy with**. Choose **docker-compose.yml** to follow this guide. The **Dockerfile** option is not covered here.

Under **Configuration**, check the **Docker Compose file** field. It holds the path of your compose file from the repository root, such as `docker-compose.yml` or `docker/production/compose.yml`. Correct it if your file lives somewhere else, then click **Re-Scan**.

![The Docker Compose file field and the Re-Scan button in xCloud](/_landing/docs/how-to-deploy-custom-docker-application-from-git-repository-image-97.png)

xCloud reads the file and lists the ports your services publish in **Primary port**. Each entry shows the port, the service name and the port inside the container, for example **3000 — documenso (3000)**. Pick the port of the service your domain should open.

What you may see next:

- **Several services publish ports**: xCloud tells you so. Choose **Use a live domain instead** and map each extra service to its own domain or subdomain and port.
- **No ports found**: the message **No exposed ports found in …** appears with a **Port (1024–65535)** field. Enter the port your app is published on.
- **A port is already used** by another site on the server: the list marks it as in use, and you cannot pick it as the primary port.

## Step 7: Set your domain

By default xCloud gives the site a **Staging domain (no DNS)**, so you can test before you point a real domain at it. To go live on your own domain right away, click **Use a live domain instead**, enter the domain and follow the DNS steps on screen.

## Step 8: Add your .env file

Open **Environment & deploy script** and tick **Provide a .env file**. Type your variables as `KEY=value`, one per line, or click **Suggest from repo** to have xCloud suggest variables from your repository. Check a suggestion before you use it.

If your compose file uses variables that have no value yet, xCloud adds them to the .env box with empty values and tells you how many it added. Fill in their values before you deploy.

**Ports set in your .env file update on their own.** Many apps let you choose their port in the .env file. When you finish editing the .env box and click anywhere outside it, xCloud scans the compose file again with your values. The note under the box says so: **Ports set through .env variables, such as HOST_PORT, refresh automatically once you finish editing your .env.**

![The .env box under Environment and deploy script, with the note that ports refresh after editing](/_landing/docs/how-to-deploy-custom-docker-application-from-git-repository-image-98.png)

After the scan, **Primary port** shows the port from your .env. For example, if your app's port defaults to 3000 and you add `PORT=8085` to your .env, the primary port changes from 3000 to 8085.

![The Primary port list showing the port set in the .env file after the automatic scan](/_landing/docs/how-to-deploy-custom-docker-application-from-git-repository-image-99.png)

If you picked a primary port yourself, xCloud keeps your choice as long as the new scan still finds that port.

### For developers: variable forms the scan understands

The port scan reads every variable form Docker Compose supports:

| In your compose file | What xCloud uses |
|---|---|
| `${VAR}` | The value of `VAR` from your .env. Unset means missing. |
| `${VAR:-default}` | `VAR` if it is set and not empty, else `default`. |
| `${VAR-default}` | `VAR` if it is set (even empty), else `default`. |
| `${VAR:?message}` / `${VAR?message}` | `VAR`. If it is unset (or empty, for `:?`), xCloud reports it as missing and adds `VAR=` to your .env. |
| `${VAR:+alt}` / `${VAR+alt}` | `alt` when `VAR` is set (and not empty, for `:+`), else nothing. |
| `$VAR` inside `ports:` | The value of `VAR`. Unset means missing. |

The example above uses the `${VAR:-default}` form: the compose file publishes `${PORT:-3000}`, so `PORT=8085` in your .env sets the port to 8085.

## Step 9: Check the deploy script and deploy

Under **Deploy script**, xCloud fills in the commands that pull, stop and start your containers, for example:

```bash
docker compose pull
docker compose down
docker compose --env-file .env up -d --build
```

xCloud adjusts these commands for you if your compose file is somewhere else or you skip the .env file.

Change them only if your app needs extra commands. A deploy script runs after every later deploy, so changing it needs the **Manage Deploy Scripts** permission. Without it, you see the standard script read-only with this message: **This is the standard script for this setup. To change it, ask a team admin for the Manage Deploy Scripts permission.** xCloud refuses any other script, but you can still deploy with the standard one. To grant the permission, see [Who can change a deploy script](/docs/team-roles-permissions-in-xcloud/#who-can-change-a-deploy-script).

![The read-only deploy script and the message for a member without the Manage Deploy Scripts permission](/_landing/docs/how-to-deploy-custom-docker-application-from-git-repository-image-104.png)

For a repository from a connected Git account, tick **Enable push-to-deploy (webhook)** to redeploy each time you push to the branch you set in Step 5.

Click **Deploy**. When the deployment finishes, click **Visit Site** next to the site name at the top of the site dashboard to open your app.

## Troubleshooting

- **A port is missing from Primary port.** The variable that sets it has no value. Find its line in the .env box (it may be one xCloud added with an empty value), fill it in and click outside the box. Still missing? Click **Re-Scan**.
- **Deploy is locked with "Enter the branch to deploy."** The **Branch** field is empty. Type the branch you want to deploy.
- **The compose file or Dockerfile is not found after you change the branch.** That branch may not have the file at that path, or the branch name has a typo. Check both, then click **Re-Scan**.
- **The wrong file was scanned.** Check the path in **Docker Compose file**, then click **Re-Scan**.
- **The scan stops with "This action is unauthorized."** To scan a repository from the team's connected Git account, you need the **Manage integrations** permission. Only a **Team Admin** can have it. Ask for it, or type your port in the **Port (1024–65535)** field.
- **The deployment gets stuck, fails to clone, or won't trigger on push.** See [Troubleshooting Git Deployments](/docs/troubleshooting-git-deployments-stuck-failed-or-not-triggering/).

To deploy a Docker app without Git, see [How to deploy Custom Docker with xCloud](/docs/how-to-deploy-custom-docker-with-xcloud/). To protect your app's data, see [Backup and restore Docker apps](/docs/backup-and-restore-docker-apps/).

## Frequently asked questions

### Can I set my app's port in the .env file instead of the compose file?

Yes. If your compose file reads its port from the .env file, add that port to your .env. When you click outside the .env box, xCloud scans the file again and the Primary port list shows the port you set.

### Why is my port missing from the Primary port list?

The variable that sets the port has no value yet. Look in your .env for a line with the variable name and an empty value, fill it in, then click outside the .env box. If the port still does not show, click Re-Scan.

### Can I deploy a branch other than main?

Yes. Type the branch name in the Branch field under Configuration. xCloud scans the compose file, the Dockerfile and the ports again on that branch, and deploys it. You don't need to click Change Repository.

### Do I need to install Docker before I deploy?

No. If Docker is not on the server yet, xCloud installs it during your first deployment. You can also install it ahead of time from the server's **Management** → **Settings** page.

If you run into any issues, feel free to reach out to our [support team](/docs/access-built-in-support-portal-in-xcloud/).
