---
title: "How to test the GitLab integration locally with Docker"
answer: "To test the Coolhand GitLab integration locally, run GitLab Community Edition in Docker with exported port 8929 and memory limits configured. Generate a personal access token with the api scope, enable local outbound requests in GitLab settings, expose your local instance via a tunnel, and connect the repository in Coolhand to test webhooks and merge requests."
category: "Integrations"
tags: ["gitlab","docker","integrations","testing","webhooks","local-development"]
published: 2026-11-28T18:55:54Z
updated: 2026-11-17T17:08:15Z
canonical_url: https://coolhandlabs.com/help/how-to-test-gitlab-integration-locally-with-docker
index_url: https://coolhandlabs.com/help.md
---

# How to test the GitLab integration locally with Docker

To test the Coolhand GitLab integration locally, run GitLab Community Edition in Docker with exported port 8929 and memory limits configured. Generate a personal access token with the api scope, enable local outbound requests in GitLab settings, expose your local instance via a tunnel, and connect the repository in Coolhand to test webhooks and merge requests.

## Why test GitLab in Docker?

Connecting Coolhand to your GitLab environment requires an instance URL, a personal access token with `api` scope, and project webhooks. When you want to verify that Coolhand properly clones repositories, opens merge requests, and processes webhook events without touching production projects or creating test clutter in an organization, you can run a local GitLab Community Edition (CE) container on your workstation.

This guide walks you through launching a resource-optimized GitLab CE container, configuring test credentials and local networking, connecting the instance to Coolhand, and triggering webhook events.

---

## Prerequisites

Before starting, ensure your system meets the following requirements:

*   **Docker Desktop or Docker Engine**: Running with at least 4 GB of allocated RAM (8 GB recommended).
*   **System Architecture**: Linux, Intel Mac, or Apple Silicon (M-series).
*   **Tools**: `curl` and `python3` (for JSON parsing in setup commands).
*   **Public Tunnel Tool (optional)**: A tunneling service such as `ngrok` or `cloudflared` if you are testing against hosted Coolhand (`app.coolhand.com`).

---

## 1. Start the GitLab container

GitLab Community Edition runs several background services by default. To make it lightweight enough for local development, tune Omnibus configuration to disable unnecessary monitoring daemons and reduce Puma web workers.

Run the following command in your terminal:

```bash
docker run --detach \
  --hostname gitlab.local \
  --name gitlab-ce \
  --publish 8929:8929 \
  --env GITLAB_OMNIBUS_CONFIG="external_url 'http://host.docker.internal:8929'; gitlab_rails['initial_root_password'] = 'Coolhand123!'; puma['worker_processes'] = 2; prometheus_monitoring['enable'] = false; alertmanager['enable'] = false; node_exporter['enable'] = false; redis_exporter['enable'] = false; postgres_exporter['enable'] = false; gitlab_exporter['enable'] = false;" \
  --shm-size 256m \
  --memory 4g \
  gitlab/gitlab-ce:17.3.1-ce.0
```

### Configuration details

*   **Port mapping (`8929:8929`)**: Setting `external_url` to port 8929 instructs GitLab's internal Nginx reverse proxy to bind to port 8929. The host port and container port must match.
*   **Initial root credentials**: Sets the default administrator password to `Coolhand123!` for username `root`.
*   **Resource caps**: Disabling Prometheus and exporter daemons saves roughly 1.5 GB of memory, allowing GitLab to boot comfortably within 4 GB.

---

## 2. Wait for GitLab initialization

GitLab takes a few minutes to run database migrations and start Puma. On Linux and Intel-based machines, startup typically takes 3 to 5 minutes. On Apple Silicon (M1/M2/M3), startup takes 10 to 20 minutes because the GitLab image runs under x86 emulation.

Poll the sign-in endpoint until it returns an HTTP `200` response:

```bash
echo "Waiting for GitLab to start..."
until [ "$(curl -s -o /dev/null -w '%{http_code}' http://localhost:8929/users/sign_in)" = "200" ]; do
  echo "  ...still starting ($(date +%H:%M:%S))"
  sleep 15
done
echo "GitLab is ready!"
```

Once ready, you can access the GitLab web interface at `http://localhost:8929` and log in with username `root` and password `Coolhand123!`.

---

## 3. Configure GitLab via API

You can configure the access token, outbound networking, and a test project with a single automated script.

Save and run the following script in your terminal:

```bash
#!/usr/bin/env bash
set -euo pipefail

GITLAB_URL="http://localhost:8929"
GITLAB_PASSWORD="Coolhand123!"

echo "1. Obtaining OAuth token..."
OAUTH_RESPONSE=$(curl -s --request POST \
  "$GITLAB_URL/oauth/token" \
  --data "grant_type=password&username=root&password=$GITLAB_PASSWORD")
OAUTH_TOKEN=$(echo "$OAUTH_RESPONSE" | python3 -c "import sys,json; print(json.load(sys.stdin)['access_token'])")

echo "2. Creating Personal Access Token..."
PAT_RESPONSE=$(curl -s --request POST \
  "$GITLAB_URL/api/v4/users/1/personal_access_tokens" \
  --header "Authorization: Bearer $OAUTH_TOKEN" \
  --header "Content-Type: application/json" \
  --data '{
    "name": "coolhand-test",
    "scopes": ["api"],
    "expires_at": "2027-01-01"
  }')
GITLAB_PAT=$(echo "$PAT_RESPONSE" | python3 -c "import sys,json; print(json.load(sys.stdin)['token'])")

echo "3. Allowing local outbound requests..."
curl -s --request PUT \
  "$GITLAB_URL/api/v4/application/settings" \
  --header "PRIVATE-TOKEN: $GITLAB_PAT" \
  --header "Content-Type: application/json" \
  --data '{
    "allow_local_requests_from_web_hooks_and_services": true,
    "allow_local_requests_from_system_hooks": true
  }' > /dev/null

echo "4. Creating test group..."
GROUP_RESPONSE=$(curl -s --request POST \
  "$GITLAB_URL/api/v4/groups" \
  --header "PRIVATE-TOKEN: $GITLAB_PAT" \
  --header "Content-Type: application/json" \
  --data '{
    "name": "coolhand-test-group",
    "path": "coolhand-test-group",
    "visibility": "private"
  }')
GROUP_ID=$(echo "$GROUP_RESPONSE" | python3 -c "import sys,json; print(json.load(sys.stdin)['id'])")

echo "5. Creating test project..."
PROJECT_RESPONSE=$(curl -s --request POST \
  "$GITLAB_URL/api/v4/projects" \
  --header "PRIVATE-TOKEN: $GITLAB_PAT" \
  --header "Content-Type: application/json" \
  --data "{
    \"name\": \"test-project\",
    \"namespace_id\": $GROUP_ID,
    \"initialize_with_readme\": true
  }")
PROJECT_ID=$(echo "$PROJECT_RESPONSE" | python3 -c "import sys,json; print(json.load(sys.stdin)['id'])")

echo ""
echo "=== GitLab Ready ==="
echo "URL:        $GITLAB_URL"
echo "PAT:        $GITLAB_PAT"
echo "Group:      coolhand-test-group"
echo "Project ID: $PROJECT_ID"
```

> **Why allow local outbound requests?** By default, GitLab blocks webhooks and service integrations from sending requests to local loopback addresses and private subnets (`127.0.0.1`, `10.x.x.x`, `192.168.x.x`, or `host.docker.internal`). Step 3 enables local outbound requests so webhooks can reach local test endpoints without being blocked.

---

## 4. Connect GitLab to Coolhand

### If testing against hosted Coolhand (`app.coolhand.com`)

Hosted Coolhand must be able to reach your local GitLab instance to inspect repositories and open merge requests. Because `localhost:8929` is private to your computer, start an HTTP tunnel:

```bash
ngrok http 8929
```

Copy the public forwarding HTTPS URL (for example, `https://abc1234.ngrok-free.app`).

### Enter connection details in Coolhand

1. In Coolhand, navigate to **Settings > GitLab Integration** (see [Connect GitLab to Coolhand](https://coolhandlabs.com/help/connect-gitlab.md) for full UI details).
2. Enter the following:
   *   **GitLab Instance URL**: Your public tunnel URL (or your local address if Coolhand runs on the same network).
   *   **GitLab Group**: `coolhand-test-group`.
   *   **Personal Access Token**: The token generated in Step 3.
3. Click **Connect GitLab**.
4. Once connected, Coolhand displays your **Webhook URL** and **Secret Token**. Keep these visible for the next step.

---

## 5. Register the webhook

On GitLab Community Edition, webhooks must be registered at the project level (group-level webhooks require GitLab Premium).

Create the webhook using the GitLab API, passing the webhook URL and secret token provided by Coolhand:

```bash
GITLAB_URL="http://localhost:8929"
GITLAB_PAT="<your-gitlab-pat>"
PROJECT_ID="<your-project-id>"

WEBHOOK_URL="<your-coolhand-webhook-url>"
WEBHOOK_TOKEN="<your-coolhand-secret-token>"

curl -s --request POST \
  "$GITLAB_URL/api/v4/projects/$PROJECT_ID/hooks" \
  --header "PRIVATE-TOKEN: $GITLAB_PAT" \
  --header "Content-Type: application/json" \
  --data "{
    \"url\": \"$WEBHOOK_URL\",
    \"token\": \"$WEBHOOK_TOKEN\",
    \"push_events\": true,
    \"merge_requests_events\": true,
    \"pipeline_events\": true,
    \"note_events\": true,
    \"enable_ssl_verification\": true
  }"
```

> **Note**: If your webhook target uses an unencrypted HTTP URL or a self-signed certificate during local testing, set `"enable_ssl_verification": false`.

---

## 6. Trigger test events

To verify that the webhook pipeline is operating properly, trigger push and merge request events directly via the GitLab API.

### Test a push event

Create a new file in the repository:

```bash
curl -s --request POST \
  "$GITLAB_URL/api/v4/projects/$PROJECT_ID/repository/files/test.txt" \
  --header "PRIVATE-TOKEN: $GITLAB_PAT" \
  --header "Content-Type: application/json" \
  --data '{
    "branch": "main",
    "content": "Testing the Coolhand local GitLab integration.",
    "commit_message": "Add test file"
  }'
```

### Test a merge request event

Create a feature branch and open a merge request:

```bash
# 1. Create a branch
curl -s --request POST \
  "$GITLAB_URL/api/v4/projects/$PROJECT_ID/repository/branches" \
  --header "PRIVATE-TOKEN: $GITLAB_PAT" \
  --header "Content-Type: application/json" \
  --data '{"branch": "feature-test", "ref": "main"}'

# 2. Add a commit to the feature branch
curl -s --request POST \
  "$GITLAB_URL/api/v4/projects/$PROJECT_ID/repository/files/feature.txt" \
  --header "PRIVATE-TOKEN: $GITLAB_PAT" \
  --header "Content-Type: application/json" \
  --data '{
    "branch": "feature-test",
    "content": "Feature branch update.",
    "commit_message": "Add feature file"
  }'

# 3. Open a merge request
curl -s --request POST \
  "$GITLAB_URL/api/v4/projects/$PROJECT_ID/merge_requests" \
  --header "PRIVATE-TOKEN: $GITLAB_PAT" \
  --header "Content-Type: application/json" \
  --data '{
    "source_branch": "feature-test",
    "target_branch": "main",
    "title": "Test merge request for Coolhand webhook"
  }'
```

In GitLab, navigate to your project's **Settings > Webhooks**, scroll down to **Project Hooks**, click **Edit** on your webhook, and inspect the **Recent Deliveries** list to verify that events show a `200 OK` response code.

---

## Troubleshooting

| Problem | Cause | Resolution |
| :--- | :--- | :--- |
| **"Could not connect to GitLab with the supplied details"** | GitLab container is still booting up or unreachable | Check container health. Ensure the sign-in readiness check returns HTTP `200` before attempting to connect. |
| **Webhook delivery fails with "local network not allowed"** | GitLab blocks local network requests by default | Enable local requests in GitLab under **Admin Area > Settings > Network > Outbound requests**, or use Step 3 of the configuration script. |
| **HTTP 502 Bad Gateway when browsing GitLab** | Internal web workers are still warming up | Wait 1 to 2 minutes after the container starts; the sign-in check might report ready slightly before all background processes stabilize. |
| **Docker container exits unexpectedly or restarts** | Out of memory | Increase Docker's memory allocation in Docker Desktop settings to at least 4 GB (8 GB is recommended). Ensure unused background exporters remain disabled. |
| **Group-level webhook returns 403 Forbidden** | Group webhooks are a GitLab Premium feature | Use project-level webhooks (`/api/v4/projects/:id/hooks`) on GitLab Community Edition. |
| **"Invalid token" when connecting in Coolhand** | Personal access token expired or missing scope | Verify that the PAT was created with the `api` scope and has not passed its expiration date. |

---

## Cleanup

When you are finished testing, stop and remove the container:

```bash
docker stop gitlab-ce && docker rm gitlab-ce
```

If you no longer need the local image, you can free up disk space by deleting it:

```bash
docker rmi gitlab/gitlab-ce:17.3.1-ce.0
```

---

## Related articles

*   [Connect GitLab to Coolhand](https://coolhandlabs.com/help/connect-gitlab.md)
*   [How to Set Up and Test the GitLab Integration via CLI and Docker](https://coolhandlabs.com/help/gitlab-cli-docker-setup.md)

---

Related:
- [Connect GitLab to Coolhand](https://coolhandlabs.com/help/connect-gitlab.md)
- [What happens when Coolhand scans a newly connected repository?](https://coolhandlabs.com/help/what-happens-when-coolhand-scans-a-repository.md)
- [Connect GitHub Enterprise Server to Coolhand](https://coolhandlabs.com/help/connect-github-enterprise-server.md)
- [Connect GitHub to Coolhand](https://coolhandlabs.com/help/connect-github.md)

[← All help articles](https://coolhandlabs.com/help.md) · [Integrations](https://coolhandlabs.com/help/category/integrations.md)
