# How to run gitlab-runner with docker

### How to run gitlab-runner with Docker

The official [document can be found here](https://docs.gitlab.com/runner/install/docker.html).

#### create a docker volume

```
docker volume create gitlab-runner-config
```

#### run the gitlab-runner container

```bash
docker run -d --name gitlab-runner --restart always \
    -v /var/run/docker.sock:/var/run/docker.sock \
    -v gitlab-runner-config:/etc/gitlab-runner \
    gitlab/gitlab-runner:latest
```

#### register a project with gitlab-ruuner container ( it is in interactive mode)

```bash
docker run --rm -it -v gitlab-runner-config:/etc/gitlab-runner gitlab/gitlab-runner register
```

#### check the configuration file of gitlab-runner

```bash
[root@docker ~]# cat /var/lib/docker/volumes/gitlab-runner-config/_data/config.toml 
concurrent = 1
check_interval = 0

[session_server]
  session_timeout = 1800

[[runners]]
  name = "gitlab-tmp-project"
  url = "https://gitlab.com/"
  token = "GssVseaD_s_dyv342WS4"
  executor = "shell"
  [runners.custom_build_dir]
  [runners.cache]
    [runners.cache.s3]
    [runners.cache.gcs]
    [runners.cache.azure]

```

#### login to it

```bash
docker exec -it $(docker ps | grep 'gitlab\-runner' | cut -d' ' -f1) bash
```

#### go into home directory

&#x20;from here you can see your pipeline output NOTE that you have set home directory ( \~ ) in your `gitlab-ci.yml` file

```bash
cd /home/gitlab-runner
```

### running the whole process in one script

```bash
#!/bin/bash
# gitlab-runner with docker
# official doc
# https://docs.gitlab.com/runner/install/docker.html

# create a docker volume
docker volume create gitlab-runner-config


# run the gitlab-runner container 
docker run -d --name gitlab-runner --restart always \
    -v /var/run/docker.sock:/var/run/docker.sock \
    -v gitlab-runner-config:/etc/gitlab-runner \
    gitlab/gitlab-runner:latest


# register a project with gitlab-ruuner container ( it is in interactive mode)
docker run --rm -it -v gitlab-runner-config:/etc/gitlab-runner gitlab/gitlab-runner register

# check the configuration file of gitlab-runner
cat /var/lib/docker/volumes/gitlab-runner-config/_data/config.toml 

# login to it
docker exec -it $(docker ps | grep 'gitlab\-runner' | cut -d' ' -f1) bash


# go into home directory , from here you can see your pipeline output
# NOTE that you have set home directory ( ~ ) in your gitlab-ci.yml file
cd /home/gitlab-runner

```

#### screenshot of the result

the top terminal is my local machine and below that is the gitlab-runner with docker

![](/files/-MVLTL4HlCSJX3Sx_Fjs)


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.shakiba.net/container/docker/gitlab-runner-with-docker.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
