Creating and Using GitLab Runners and Executors
80%
Using Docker Runner
Repeat the same procedure to create a Docker runner. The only difference is that you need to choose "Docker" as the platform when creating the runner. Use the following tag: docker.
Install Docker:
curl -fsSL https://get.docker.com -o get-docker.sh
bash get-docker.sh
Start the Docker service:
systemctl start docker
Check the status of the Docker service:
systemctl status docker
Launch the GitLab runner container:
docker run -d --name gitlab-runner --restart always \
-v /srv/gitlab-runner/config:/etc/gitlab-runner \
-v /var/run/docker.sock:/var/run/docker.sock \
gitlab/gitlab-runner:latest
Now to use the Docker runner with a specific image based on your needs. In our case the image is python:3.12. The token should be exported as an environment variable as we did before. Finally, you need to run the following command.
gitlab-runner register \
--url https://gitlab.com/ \
--registration-token $GITLAB_RUNNER_TOKEN \
--executor docker \
--description "My Docker Runner" \
--docker-image "python:3.12" \
--non-interactive
Update the ".gitlab-ci.yml" file to use the Docker runner. Here is the updated ".gitlab-ci.yml" file:
cat < $HOME/todo/app/.gitlab-ci.yml && \
cd $HOME/todo/app && \
git add . && \
git commit -m "Add a GitLab CI/CD pipeline" && \
git push origin main
# Define the stages of the pipeline.
stages:
- build
- test
# Define the build stage
build:
stage: buildCloud Native CI/CD with GitLab
From Commit to Production ReadyEnroll now to unlock all content and receive all future updates for free.
