You have to execute the command from the root folder of your git repository/project:

 $ ls -a
 ./
 ../
 .git/
 .gitignore
 .gitlab-ci.yml
 Makefile

 $ gitlab-runner exec docker <job_name>

You are using docker commands which you shouldn't as gitlab-runner already uses those under the hood. See $ gitlab-runner exec docker --help for more info on the command.

Answer from 13013SwagR on Stack Overflow
🌐
GitLab
docs.gitlab.com › gitlab docs › administer › administer gitlab runner › runner executors › docker
Docker executor | GitLab Docs
Use the registry.gitlab.com/gitlab-org/step-runner:v0 image if it includes the dependencies you need to run your job. Running a step that runs a Docker container must adhere to the same configuration parameters and constraints as traditional scripts. For example, you must use Docker-in-Docker. This ...
Top answer
1 of 2
2

You have to execute the command from the root folder of your git repository/project:

 $ ls -a
 ./
 ../
 .git/
 .gitignore
 .gitlab-ci.yml
 Makefile

 $ gitlab-runner exec docker <job_name>

You are using docker commands which you shouldn't as gitlab-runner already uses those under the hood. See $ gitlab-runner exec docker --help for more info on the command.

2 of 2
0

I also came across a similar issue when using VS Code with remote containers and Docker Desktop (WSL2).

I debugged the problem by adding in a --pre-get-sources-script=ls -l "repo_directory", i.e. in the OP's case:

# docker run --name=runner --privileged -t --rm \
 -v /var/run/docker.sock:/var/run/docker.sock  \
 -v /tmp/.gitlab-runner/:/etc/gitlab-runner \
 -v {PWD} \
 --workdir $PWD \
 --pre-get-sources-script=ls -l /home/fox/Work/docker/core-application/../.git/modules/core-application \
 gitlab/gitlab-runner exec docker \
  --builds-dir /tmp/builds/ Rspec

In my case, the directory listing (ls -l ...) came up empty! I'm assuming that it mounts the directory as a volume within the container as the same name (/fubar:/fubar), which in my case isn't going to work as it is Docker Desktop with vscode remote containers.

My fix was was to add my named volume as a parameter to a secondary directory, and then setting the --clone-url to point to that directory.

Something like:

# pwd
/workspace/fubar
# gitlab-runner --debug exec docker \
  --docker-volumes vscode-workspace:/workspace2 \
  --clone-url=file:///workspace2/fubar \
  validate;
[output truncated]
...
Starting container 3d49d8e8b977177f34beeae3ae5f09eba288332e109ad79f133e0f160377908b ...  job=1 project=0
Fetching changes...
Initialized empty Git repository in /builds/project-0/.git/
Created fresh repository.
Checking out d1a39a4d as detached HEAD (ref is feature/FU-123)...

Skipping Git submodules setup
Executing build stage                               build_stage=restore_cache job=1 project=0
Skipping stage (nothing to do)                      build_stage=restore_cache job=1 project=0
Executing build stage                               build_stage=download_artifacts job=1 project=0
Skipping stage (nothing to do)                      build_stage=download_artifacts job=1 project=0
Executing build stage                               build_stage=step_script job=1 project=0
Executing "step_script" stage of the job script
...

I had originally tried changing the --pre-get-sources-script to be cp -R /workspace2/fubar /workspace/ but that complained that the target directory was read-only. Using the --clone-url=file:///workspace2/fubar worked, so I've left it that way.

Discussions

How to use gitlab-runner exec docker correclty - GitLab CI/CD - GitLab Forum
I am trying to run the gitlab pipeline jobs locally in order to test and debug. Here is what I did Installed gitlab-runner on my local machine. sudo gitlab-runner exec docker --docker-privileged --builds-dir /tmp/builds --docker-volumes /home/fox/Work/docker/core-application:/core-application ... More on forum.gitlab.com
🌐 forum.gitlab.com
0
December 15, 2020
How to use the docker gitlab-runner to exec stages locally - Stack Overflow
I have setup a gitlab runner in docker on my local machine. It all is working fine. When the pipeline starts, the runner seems to handle the workload · But, I would like to do this locally. For example, if you downloaded the gitlab-runner executable, you can run stages locally More on stackoverflow.com
🌐 stackoverflow.com
gitlab-runner exec with dind (docker in docker) minimal working example - Stack Overflow
gitlab-runner exec docker --docker-privileged --docker-pull-policy if-not-present --docker-tlsverify=false test ... ERROR: Cannot connect to the Docker daemon at tcp://docker:2375. Is the docker daemon running? I have saw this issue and many others. But I couldn't find a minimal working example ... More on stackoverflow.com
🌐 stackoverflow.com
June 29, 2020
Use GitLab CI to run tests locally? - Stack Overflow
If a GitLab project is configured on GitLab CI, is there a way to run the build locally? I don't want to turn my laptop into a build "runner", I just want to take advantage of Docker and .gitlab-c... More on stackoverflow.com
🌐 stackoverflow.com
🌐
GitLab
gitlab.com › gitlab.org › gitlab-runner › #4275
How to use exec command with the dockerized version of gitlab-runner (#4275) · Issues · GitLab.org / gitlab-runner · GitLab
Summary Trying to debug a failing gitlab ci job by using the docker gitlab-runner exec functionality. But it fails right away...
🌐
GitLab
docs.gitlab.com › gitlab docs › install › configure gitlab runner › commands
GitLab Runner commands | GitLab Docs
gitlab-runner run-single -u http://gitlab.example.com -t my-runner-token --executor docker --docker-image ruby:3.3
🌐
Medium
medium.com › @BuildWithLal › dockerized-gitlab-ci-register-docker-executor-as-a-gitlab-runner-71799352c9ac
Dockerized GitLab CI: Register Docker Executor as a GitLab Runner | by Lal Zada | Medium
October 10, 2024 - When we want to execute a job using docker, GitLab Runner can create a container on our host machine using this docker.sock file, run the job and then terminate once the job is done.
🌐
Datawookie
datawookie.dev › blog › 2021 › 03 › install-gitlab-runner-with-docker
Install GitLab Runner with Docker – datawookie
March 21, 2021 - You can stop the runners using the stop command. ... And start them using the start command. ... You can perform both actions in sequence with the restart command. docker exec -it gitlab-runner gitlab-runner restart
🌐
GitLab
docs.gitlab.com › gitlab docs › install › install gitlab runner › docker
Run GitLab Runner in a container | GitLab Docs
GITLAB_RUNNER_IMAGE_TYPE=gitlab-runner-helper \ GITLAB_RUNNER_IMAGE_TAG=x86_64-v18.10.1 \ docker build -t $GITLAB_RUNNER_IMAGE_TYPE:$GITLAB_RUNNER_IMAGE_TAG \ --build-arg GITLAB_RUNNER_IMAGE_TYPE=$GITLAB_RUNNER_IMAGE_TYPE \ --build-arg GITLAB_RUNNER_IMAGE_TAG=$GITLAB_RUNNER_IMAGE_TAG \ -f alpine-upgrade/Dockerfile alpine-upgrade · Some distributions, like CentOS, Red Hat, and Fedora use SELinux (Security-Enhanced Linux) by default to enhance the security of the underlying system. Use caution with this configuration. ... To use the Docker executor to run builds in containers, runners need access to /var/run/docker.sock.
Find elsewhere
🌐
GitLab
gitlab.com › gitlab.org › gitlab-runner › #3295
Use local docker images with gitlab-runner exec docker (#3295) · Issues · GitLab.org / gitlab-runner · GitLab
I would like to debug my build locally but I would like to avoid having to build the docker image once again (I have it locally to develop, but I would have to build it again for gitlab-runner). In order to do so, I'm mounting a volume of the Docker socket file and passing it to the docker executor, but docker can't see my images (in my `test` stage, I have a `docker images` to see what is available): ```sh $ docker run --rm -it -v "$PWD":"$PWD" --workdir "$PWD" -v /var/run/docker.sock:/var/run/docker.sock gitlab/gitlab-runner:alpine-v10.7.1 exec docker --docker-privileged --docker-pull-policy if-not-present --docker-volumes /var/run/docker.sock:/var/run/docker.sock test WARNING: You most probably have uncommitted changes.
🌐
GitLab
forum.gitlab.com › gitlab ci/cd
How to use gitlab-runner exec docker correclty - GitLab CI/CD - GitLab Forum
December 15, 2020 - Here is what I did Installed gitlab-runner on my local machine. sudo gitlab-runner exec docker --docker-privileged --builds-dir /tmp/builds --docker-volumes /home/fox/Work/docker/core-application:/core-application Rspec This gives Runtime platform ...
🌐
GitLab
docs.gitlab.com › gitlab docs › use gitlab › use ci/cd to build your application › jobs › docker › run ci/cd jobs in docker containers
Run your CI/CD jobs in Docker containers | GitLab Docs
To use GitLab Runner with Docker you need to register a runner that uses the Docker executor. This example shows how to set up a temporary template to supply services:
🌐
LinkedIn
linkedin.com › pulse › how-execute-gitlab-ci-docker-your-local-machine-shubham-takode
How to execute GitLab CI with Docker on your local machine.
February 25, 2022 - #Go to your project directory and run (make sure there is gitlab-ci.yml) $sudo gitlab-runner exec docker build #where build is the stage from your .gitlab-ci.yml you want to execute
🌐
TestDriven.io
testdriven.io › blog › gitlab-ci-docker
Deploying Self-Hosted GitLab CI Runners with Docker | TestDriven.io
October 29, 2021 - Before we update the concurrency options, add a new runner: $ docker-compose exec gitlab-runner-container \ gitlab-runner register \ --non-interactive \ --url <YOUR-GITLAB-URL> \ --registration-token <YOUR-GITLAB-REGISTRATION-TOKEN> \ --executor docker \ --description "Sample Runner 2" \ --docker-image "docker:stable" \ --docker-volumes /var/run/docker.sock:/var/run/docker.sock
🌐
GitHub
gist.github.com › NikiforovAll › 7294ce1a72bdcfbf4159896853589b9f
GitLab Runner + Docker · GitHub
docker run -d \ --name gitlab-runner \ --restart always \ -v $PWD:$PWD \ -v /var/run/docker.sock:/var/run/docker.sock \ gitlab/gitlab-runner:latest · Run job: docker exec -it -w $PWD gitlab-runner gitlab-runner exec docker <jobName>
🌐
GitHub
github.com › soerenmetje › docker-gitlab-runner
GitHub - soerenmetje/docker-gitlab-runner: Run a Gitlab runner inside a Docker container · GitHub
Example: 'frontend' DOCKER_ADDITIONAL_IMG_TAG: "" # OPTIONAL DOCKER_BUILD_DIR: "." # OPTIONAL DOCKER_DOCKERFILE: "" # OPTIONAL services: - docker:23.0-dind before_script: - docker info - echo logging in gitlab-ci-token to $CI_REGISTRY - docker login -u gitlab-ci-token -p $CI_BUILD_TOKEN $CI_REGISTRY # check gitlab runner config if not working script: - | if [ -z "$DOCKER_IMG_NAME" ]; then echo "CI job variable DOCKER_IMG_NAME must be set.
Author: soerenmetje
🌐
Geek Cookbook
geek-cookbook.funkypenguin.co.nz › recipes › gitlab-runner
How to run Gitlab Runner in Docker |・∀・
From your GitLab UI, you can retrieve a "token" necessary to register a new runner. To register the runner, you can either create config.toml in each runner's bind-mounted folder (example below), or just docker exec into each runner container and execute gitlab-runner register to interactively ...
🌐
OneUptime
oneuptime.com › home › blog › how to set up docker with gitlab ci runner
How to Set Up Docker with GitLab CI Runner
January 16, 2026 - # Add gitlab-runner user to docker group sudo usermod -aG docker gitlab-runner # Restart runner sudo gitlab-runner restart · # Use alias for service hostname services: - name: postgres:15 alias: db # Connect using "db" as hostname # Wait for ...
🌐
GitHub
gist.github.com › DrPsychick › b92c2653c1132c3be6da2c3bb42905d4
Run gitlab-ci jobs locally · GitHub
mount the certs: exec docker --docker-volumes "/certs/client" 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>
🌐
Stack Overflow
stackoverflow.com › questions › 62629945 › gitlab-runner-exec-with-dind-docker-in-docker-minimal-working-example
gitlab-runner exec with dind (docker in docker) minimal working example - Stack Overflow
June 29, 2020 - image: docker:18 varibales: DOCKER_DRIVER: "overlay2" DOCKER_HOST: tcp://docker:2375 test: services: - "docker:18-dind" script: - docker info ... gitlab-runner exec docker --docker-privileged --docker-pull-policy if-not-present --docker-tls...
🌐
Stack Overflow
stackoverflow.com › questions › 32933174 › use-gitlab-ci-to-run-tests-locally
Use GitLab CI to run tests locally? - Stack Overflow
If a GitLab project is configured on GitLab CI, is there a way to run the build locally? I don't want to turn my laptop into a build "runner", I just want to take advantage of Docker and .gitlab-c...