Step 1 – Install Latest Version of Docker
Step 2 – Run “gitlab-runner” command in the container
# Use local system volume mounts to start the 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
$ docker logs gitlab-runnerCode language: PHP (php)
Step 3 – Register the runner
The following steps describe launching a short-lived gitlab-runner container to register the container you created during install. After you finish registration, the resulting configuration is written to your chosen configuration volume (for example, /srv/gitlab-runner/config) and is loaded by the runner using that configuration volume.
To register a runner using a Docker container: Run the register command based on the mount type:
$ docker run --rm -it -v /srv/gitlab-runner/config:/etc/gitlab-runner gitlab/gitlab-runner register
- Enter your GitLab instance URL (also known as the gitlab-ci coordinator URL).
- Enter the token you obtained to register the runner.
- Enter a description for the runner. You can change this value later in the GitLab user interface.
- Enter the tags associated with the runner, separated by commas. You can change this value later in the GitLab user interface.
- Enter any optional maintenance note for the runner.
- Provide the runner executor. For most use cases, enter docker.
- If you entered docker as your executor, you are asked for the default image to be used for projects that do not define one in .gitlab-ci.yml.Code language: JavaScript (javascript)
Reference
Example of .gitlab-ci.yml
stages:
- publish
- deploy
variables:
TAG_LATEST: $CI_REGISTRY_IMAGE/$CI_COMMIT_REF_NAME:latest
TAG_COMMIT: $CI_REGISTRY_IMAGE/$CI_COMMIT_REF_NAME:$CI_COMMIT_SHORT_SHA
publish:
image: docker:latest
stage: publish
services:
- docker:dind
script:
- docker build -t $TAG_COMMIT -t $TAG_LATEST .
- docker login -u gitlab-ci-token -p $CI_BUILD_TOKEN $CI_REGISTRY
- docker push $TAG_COMMIT
- docker push $TAG_LATEST
deploy:
image: alpine:latest
stage: deploy
tags:
- deployment
script:
- chmod og= $ID_RSA
- apk update && apk add openssh-client
- ssh -i $ID_RSA -o StrictHostKeyChecking=no $SERVER_USER@$SERVER_IP "docker login -u gitlab-ci-token -p $CI_BUILD_TOKEN $CI_REGISTRY"
- ssh -i $ID_RSA -o StrictHostKeyChecking=no $SERVER_USER@$SERVER_IP "docker pull $TAG_COMMIT"
- ssh -i $ID_RSA -o StrictHostKeyChecking=no $SERVER_USER@$SERVER_IP "docker container rm -f my-app || true"
- ssh -i $ID_RSA -o StrictHostKeyChecking=no $SERVER_USER@$SERVER_IP "docker run -d -p 80:80 --name my-app $TAG_COMMIT"
environment:
name: production
url: http://your_server_IP
only:
- masterCode language: PHP (php)
image: node:4.2.2
variables:
POSTGRES_USER: testuser
POSTGRES_PASSWORD: testpass
services:
- postgres:9.5.0
all_tests:
script:
- npm install
- node ./specs/start.js
image: node:4.2.2
cache:
paths:
- node_modules/
stages:
- test
test_async:
stage: test
script:
- npm install
- node ./specs/start.js ./specs/async.spec.js
tags:
- docker
test_db:
stage: test
services:
- postgres:9.5.0
script:
- npm install
- node ./specs/start.js ./specs/db-postgres.spec.js
tags:
- docker
Code language: HTTP (http)
https://gitlab.com/gitlab-examples/nodejs/-/tree/master/
I’m Rajesh Kumar, a DevOps, SRE, DevSecOps, Cloud, and Platform Engineering expert passionate about sharing practical knowledge, real-world experiences, and industry best practices. I have worked at Cotocus and regularly write about technology, travel, investing, health, product reviews, and digital marketing through my various platforms.
I publish technical articles at DevOps School, travel stories at Holiday Landmark, stock market insights at Stocks Mantra, health and fitness guidance at My Medic Plus, product reviews at TrueReviewNow, and SEO and digital marketing strategies at Wizbrand.
Find Trusted Cardiac Hospitals
Compare heart hospitals by city and services โ all in one place.
Explore Hospitals