Feedback

Chat Icon

Cloud Native CI/CD with GitLab

From Commit to Production Ready

Creating and Using GitLab Runners and Executors
81%

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 --version 29.2.0

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 to update the runner configuration (from Linux runner to Docker runner):

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 command to do that:

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

Cloud Native CI/CD with GitLab

From Commit to Production Ready

Enroll now to unlock all content and receive all future updates for free.