Since a few months ago this is possible using gitlab-runner:

gitlab-runner exec docker my-job-name

Note that you need both docker and gitlab-runner installed on your computer to get this working.

You also need the image key defined in your .gitlab-ci.yml file. Otherwise won't work.

Here's the line I currently use for testing locally using gitlab-runner:

gitlab-runner exec docker test --docker-volumes "/home/elboletaire/.ssh/id_rsa:/root/.ssh/id_rsa:ro"

Note: You can avoid adding a --docker-volumes with your key setting it by default in /etc/gitlab-runner/config.toml. See the official documentation for more details. Also, use gitlab-runner exec docker --help to see all docker-based runner options (like variables, volumes, networks, etc.).

Due to the confusion in the comments, I paste here the gitlab-runner --help result, so you can see that gitlab-runner can make builds locally:

   gitlab-runner --help
NAME:
   gitlab-runner - a GitLab Runner

USAGE:
   gitlab-runner [global options] command [command options] [arguments...]
   
VERSION:
   1.1.0~beta.135.g24365ee (24365ee)
   
AUTHOR(S):
   Kamil Trzciński <[email protected]> 
   
COMMANDS:
   exec         execute a build locally
   [...]
   
GLOBAL OPTIONS:
   --debug          debug mode [$DEBUG]
   [...]

As you can see, the exec command is to execute a build locally.

Even though there was an issue to deprecate the current gitlab-runner exec behavior, it ended up being reconsidered and a new version with greater features will replace the current exec functionality.

Note that this process is to use your own machine to run the tests using docker containers. This is not to define custom runners. To do so, just go to your repo's CI/CD settings and read the documentation there. If you wanna ensure your runner is executed instead of one from gitlab.com, add a custom and unique tag to your runner, ensure it only runs tagged jobs and tag all the jobs you want your runner to be responsible of.

Unofficial alternative gitlab-ci-local

There's an unofficial package which looks promising, with more features than the official gitlab-runner exec: https://github.com/firecow/gitlab-ci-local

It allows you to run gitlab pipelines locally as shell executor or docker executor.

Answer from elboletaire on Stack Overflow
Top answer
1 of 11
237

Since a few months ago this is possible using gitlab-runner:

gitlab-runner exec docker my-job-name

Note that you need both docker and gitlab-runner installed on your computer to get this working.

You also need the image key defined in your .gitlab-ci.yml file. Otherwise won't work.

Here's the line I currently use for testing locally using gitlab-runner:

gitlab-runner exec docker test --docker-volumes "/home/elboletaire/.ssh/id_rsa:/root/.ssh/id_rsa:ro"

Note: You can avoid adding a --docker-volumes with your key setting it by default in /etc/gitlab-runner/config.toml. See the official documentation for more details. Also, use gitlab-runner exec docker --help to see all docker-based runner options (like variables, volumes, networks, etc.).

Due to the confusion in the comments, I paste here the gitlab-runner --help result, so you can see that gitlab-runner can make builds locally:

   gitlab-runner --help
NAME:
   gitlab-runner - a GitLab Runner

USAGE:
   gitlab-runner [global options] command [command options] [arguments...]
   
VERSION:
   1.1.0~beta.135.g24365ee (24365ee)
   
AUTHOR(S):
   Kamil Trzciński <[email protected]> 
   
COMMANDS:
   exec         execute a build locally
   [...]
   
GLOBAL OPTIONS:
   --debug          debug mode [$DEBUG]
   [...]

As you can see, the exec command is to execute a build locally.

Even though there was an issue to deprecate the current gitlab-runner exec behavior, it ended up being reconsidered and a new version with greater features will replace the current exec functionality.

Note that this process is to use your own machine to run the tests using docker containers. This is not to define custom runners. To do so, just go to your repo's CI/CD settings and read the documentation there. If you wanna ensure your runner is executed instead of one from gitlab.com, add a custom and unique tag to your runner, ensure it only runs tagged jobs and tag all the jobs you want your runner to be responsible of.

Unofficial alternative gitlab-ci-local

There's an unofficial package which looks promising, with more features than the official gitlab-runner exec: https://github.com/firecow/gitlab-ci-local

It allows you to run gitlab pipelines locally as shell executor or docker executor.

2 of 11
189

Deprecated since 2024-05 (see edit)

Only for gitlab-runner < 17.0.

  • See gitlab issue.
  • See gitlab docu

I use this docker-based approach:

Edit: 2024-05

docker run --entrypoint bash --rm -w "$PWD" -v "PWD" -v /var/run/docker.sock:/var/run/docker.sock gitlab/gitlab-runner:v15.11.1 -c 'git config --global --add safe.directory "*";gitlab-runner exec docker test'

Thanks to user Ivo Smits who reported a successful test with gitlab-runner:v15.11.1

Edit: 2022-10

For all git versions > 2.35.2. You must add safe.directory within the container to avoid fatal: detected dubious ownership in repository at.... This also true for patched git versions < 2.35.2. The old command will not work anymore.

Details

0. Create a git repo to test this answer

mkdir my-git-project
cd my-git-project
git init
git commit --allow-empty -m"Initialize repo to showcase gitlab-runner locally."

1. Go to your git directory

cd my-git-project

2. Create a .gitlab-ci.yml

Example .gitlab-ci.yml

image: alpine

test:
  script:
    - echo "Hello Gitlab-Runner"

3. Create a docker container with your project dir mounted

docker run -d \
  --name gitlab-runner \
  --restart always \
  -v "PWD" \
  -v /var/run/docker.sock:/var/run/docker.sock \
  gitlab/gitlab-runner:latest

(-d) run container in background and print container ID

(--restart always) or not?

(-v "PWD") Mount current directory into the current directory of the container - Note: On Windows you could bind your dir to a fixed location, e.g. -v "${PWD}:/opt/myapp". Also $PWD will only work at powershell not at cmd

(-v /var/run/docker.sock:/var/run/docker.sock) This gives the container access to the docker socket of the host so it can start "sibling containers" (e.g. Alpine).

(gitlab/gitlab-runner:latest) Just the latest available image from dockerhub.

4. Execute with

Avoid fatal: detected dubious ownership in repository at... More info

docker exec -it -w $PWD gitlab-runner git config --global --add safe.directory "*"

Actual execution

docker exec -it -w $PWD gitlab-runner gitlab-runner exec docker test
#                ^          ^           ^            ^     ^      ^
#                |          |           |            |     |      |
#               (a)        (b)         (c)          (d)   (e)    (f)

(a) Working dir within the container. Note: On Windows you could use a fixed location, e.g. /opt/myapp.

(b) Name of the docker container

(c) Execute the command "gitlab-runner" within the docker container

(d)(e)(f) run gitlab-runner with "docker executer" and run a job named "test"

5. Prints

...
Executing "step_script" stage of the job script
$ echo "Hello Gitlab-Runner"
Hello Gitlab-Runner
Job succeeded
...

Note: The runner will only work on the commited state of your code base. Uncommited changes will be ignored. Exception: The .gitlab-ci.yml itself does not have be commited to be taken into account.

Note: There are some limitations running locally. Have a look at limitations of gitlab runner locally.

🌐
GitLab
docs.gitlab.com › runner
GitLab Runner | GitLab Docs
Runner: A configured instance of GitLab Runner that can execute jobs. Depending on the type of executor, this machine could be local to the runner manager (shell or docker executor) or a remote machine created by an autoscaler (docker-autoscaler or kubernetes).
Discussions

How to setup both GitLab and Runner on local machine correctly?
To accomplish this, I decided to setup 2 containers on my local machine (GitLab Instance and Runner) via docker compose and it worked fine until I tried to run my job. Problem: job (runner container) can’t see localhost hosted git repo Job error: Docker compose YAML: version: '3.6' services: ... More on forum.gitlab.com
🌐 forum.gitlab.com
0
0
July 5, 2023
How to test an entire pipeline locally, that contains jobs with dependencies?
Debugging .gitlab-ci.yml locally with jobs that contain dependencies I’m using the GitLab runner to debug locally this .gitlab-ci.yml image: "openfoam-v2012_ubuntu:focal" stages: - build - run - visualize # - test build_apps: stage: build script: - source /opt/OpenFOAM/OpenFOAM-v2012/etc/bashrc ... More on forum.gitlab.com
🌐 forum.gitlab.com
0
0
March 22, 2021
Running the entire GitLab CI pipeline locally with external GitLab runners
What you seem to be asking is can you run gitlab localy to run the pipelines, but use remote runners. The answer is yes, but with the following caveats. You can install gitlab on your local machine. Runners can only be registered with one system, so if you register them with your local system, they cant also be connected to gitlab.com You will have to have an inbound https connection from the runner to your local instance of gitlab, so it can register and pickup jobs. More on reddit.com
🌐 r/gitlab
3
7
November 13, 2022
Gitlab-runner local build
I am trying to followed this example: https://stackoverflow.com/questions/32933174/use-gitlab-ci-to-run-tests-locally The above suggests: gitlab-runner exec docker my-job-name I am using GITLAB-RUNNER VERSION: 17.2.0 (6428c288) I do not use docker and I do not want to use docker. More on forum.gitlab.com
🌐 forum.gitlab.com
0
0
August 13, 2024
🌐
GitHub
github.com › firecow › gitlab-ci-local
GitHub - firecow/gitlab-ci-local: Tired of pushing to test your .gitlab-ci.yml? · GitHub
Run gitlab pipelines locally as shell executor or docker executor.
Starred by 3.8K users
Forked by 202 users
Languages   TypeScript 96.7% | JavaScript 3.0%
🌐
GitLab
forum.gitlab.com › gitlab ci/cd
How to setup both GitLab and Runner on local machine correctly? - GitLab CI/CD - GitLab Forum
July 5, 2023 - To accomplish this, I decided to setup 2 containers on my local machine (GitLab Instance and Runner) via docker compose and it worked fine until I tried to run my job. Problem: job (runner container) can’t see localhost hosted git repo Job error: Docker compose YAML: version: '3.6' services: ...
🌐
GitLab
docs.gitlab.com › runner › install
Install GitLab Runner | GitLab Docs
Manually download and install the GitLab Runner binary on Linux.
🌐
GitLab
docs.gitlab.com › runner › commands
GitLab Runner commands | GitLab Docs
Restore the cache archive from a locally or externally stored file. Below are some common pitfalls. Usually the service related commands require administrator privileges: On Unix (Linux, macOS, FreeBSD) systems, prefix gitlab-runner with sudo
🌐
GitLab
docs.gitlab.com › tutorials › create_register_first_runner
Tutorial: Create, register, and run your own project runner | GitLab Docs
July 5, 2023 - Before you can create, register, and run a runner, you must install GitLab Runner on a local computer.
Find elsewhere
🌐
DEV Community
dev.to › ishmam_abir › cicd-on-local-gitlab-server-setup-gitlab-runner-self-hosted-gitlab-37nf
CI/CD on Local Gitlab server| Setup GitLab Runner | Self-hosted GitLab - DEV Community
November 15, 2025 - Our runner container is running, but it's not authenticated with our server. We need to "register" it. ... Log into your local GitLab server (http://localhost:8080) as the root user.
🌐
BrowserStack
browserstack.com › home › guide › how to run test on gitlab ci locally
How to run test on GitLab CI Locally | BrowserStack
May 30, 2023 - When your gitlab-ci.yml configuration file is added to the repository, GitLab can ascertain it and execute your scripts with the GitLab Runner app. This app functions precisely like your terminal and predominantly helps you reproduce production-like scripts. ... # Adding variables to set maven local environment variables: MAVEN_OPTS: -Dmaven.repo.local=.m2/repository # Docker image to use latest maven distribution image: maven:latest # setting up maven lifecycle stages stages: - build - test - package - deploy # setting up cache paths cache: paths: - .m2/repository - target build_job: stage: b
🌐
GitLab
forum.gitlab.com › gitlab ci/cd
How to test an entire pipeline locally, that contains jobs with dependencies? - GitLab CI/CD - GitLab Forum
March 22, 2021 - Debugging .gitlab-ci.yml locally with jobs that contain dependencies I’m using the GitLab runner to debug locally this .gitlab-ci.yml image: "openfoam-v2012_ubuntu:focal" stages: - build - run - visualize # - test build_apps: stage: build script: - source /opt/OpenFOAM/OpenFOAM-v2012/etc/bashrc || true - ./Allwmake - ls $FOAM_USER_APPBIN - ls $FOAM_APPBIN artifacts: paths: - /root/OpenFOAM/-v2012/platforms/linux64GccDPInt32Opt/bin/foamTestFvcReco...
🌐
Reddit
reddit.com › r/gitlab › running the entire gitlab ci pipeline locally with external gitlab runners
r/gitlab on Reddit: Running the entire GitLab CI pipeline locally with external GitLab runners
November 13, 2022 -

Is there a way to run the entire GitLab CI pipeline on the local host, where it uses the same GitLab runners that are located on external compute resources, such as an external build server?

I know of the gitlab-runner exec command, but as I understand it, that command uses the local host as the GitLab runner. Is there a way of using the command the same way, but with the external GitLab runners that are already used in the CI pipeline when pushing to the cloud? A thought that came to mind is to use a script to ssh into an external host and then use the GitLab runner command to perform all jobs in the gitlab-ci.yml file. However, this will require the local host to link the repository to the external host somehow before executing the pipeline. This method also seems tedious when having multiple external computers with a GitLab runner. Does anyone have any better suggestions?

🌐
GitHub
github.com › daaru00 › gitlab-runners-local
GitHub - daaru00/gitlab-runners-local: Run Gitlab runners locally · GitHub
version: '3' services: project1: build: . container_name: "gitlab-runner-project1" #change this with your repository name environment: REGISTRATION_TOKEN: "<registration token here>" #add repository-specific registration token volumes: - /var/run/docker.sock:/var/run/docker.sock project2: build: .
Author   daaru00
🌐
Testmuai
testmuai.com › testmu ai › blog › how to use gitlab ci to run tests locally | testmu ai
How To Use GitLab CI To Run Tests Locally | TestMu AI (Formerly LambdaTest)
December 28, 2025 - That is why it is super helpful to run the CI docker image locally, to iron out quirks based on the rest of the world. And by running the GitLab CI Runner itself, you can do just that. It will pick up the .gitlab-ci.yml of your project and run it via Docker locally.
🌐
Medium
medium.com › @umutuluer › how-to-test-gitlab-ci-locally-f9e6cef4f054
How to Test Gitlab Ci Locally. I have a gitlab-ci.yml file and I want… | by Umut Uluer | Medium
October 31, 2018 - These will show in your Project Settings > CI / CD > Runners tab. Now, lets create gitlab-ci.yml file in project root directory. I will use two stage in this section. Test and deploy. Also, I will define cache file locations, variables that used by script and lastly, commands are in stages. stages: - test - deploy cache: paths: - vendor/ - node_modules/ - storage/framework/cache variables: DEPLOYMENT_PATH: /usr/local/my_project PROJECT_ROOT: /home/gitlab-runner/my_project my_project_test: stage: test script: - composer install - php vendor/bin/phpunit --colors my_project_deploy: stage: deploy script: - rsync -a -e 'ssh -p 1881' --delete-before -r ${PROJECT_ROOT}/* root@$STAGE_SERVER:${DEPLOYMENT_PATH}
🌐
GitLab
forum.gitlab.com › gitlab ci/cd
Gitlab-runner local build - GitLab CI/CD - GitLab Forum
August 13, 2024 - I am trying to followed this example: https://stackoverflow.com/questions/32933174/use-gitlab-ci-to-run-tests-locally The above suggests: gitlab-runner exec docker my-job-name I am using GITLAB-RUNNER VERSION: 17.2.0 (6428c288) I do not use docker and I do not want to use docker.
🌐
Baeldung
baeldung.com › home › devops › guide to using gitlab ci to run tests locally
Guide to Using GitLab CI to Run Tests Locally | Baeldung on Ops
January 31, 2025 - Let’s install version 13.3.0 of the gitlab-runner tool. We can follow the install guide for our operating system and replace the latest keyword with v13.3.0 in the download path: $ sudo curl --output /usr/local/bin/gitlab-runner https://gitlab-runner-downloads.s3.amazonaws.com/v13.3.0/bi...
🌐
GitLab
gitlab.com › gitlab.org › gitlab-runner › #1359
How to run gitlab runner full localy? (#1359) · Issues · GitLab.org / gitlab-runner · GitLab
May 30, 2016 - I want to test some gitlab runner features related to my project, but I cant without committing and pushing changes to a repository. Every time after firing a...
🌐
GitHub
gist.github.com › DrPsychick › b92c2653c1132c3be6da2c3bb42905d4
Run gitlab-ci jobs locally · GitHub
docker run --rm --name gitlab-runner -w $PWD \ -v $PWD:$PWD -v /var/run/docker.sock:/var/run/docker.sock \ gitlab/gitlab-runner:latest exec docker <job>
🌐
DBI Services
dbi-services.com › accueil › run 2 specific gitlab runners in local containers for ci/cd pipeline
Run 2 specific GitLab Runners in local containers for CI/CD Pipeline
August 5, 2022 - enb@DBI-LT-ENB project1 % docker run -d --name gitlab-runner2 --restart always \ -v /Users/Shared/gitlab-runner/config2:/etc/gitlab-runner \ gitlab/gitlab-runner:latest · Just change the name used for this Runner as well as the local folder for the volume mount.