How to run GitLab and GitLab Runner locally

In order to run GitLab and GitLab Runner on your local PC, simplest way is to create docker-compose.yml file and add the following content to it:

version: '3.7'
services:
  gitlab-web:
    image: gitlab/gitlab-ce:latest
    hostname: localhost
    restart: unless-stopped
    environment:
      GITLAB_OMNIBUS_CONFIG: |
        gitlab_rails['gitlab_shell_ssh_port'] = 22
    ports:
      - "80:80"
      - "22:22"
    volumes:
      - ./gitlab/config/gitlab:/etc/gitlab
      - ./gitlab/data/gitlab:/var/opt/gitlab
      - ./gitlab/logs:/var/log/gitlab
    networks:
      - gitlab-network

  gitlab-runner:
    image: gitlab/gitlab-runner:alpine
    restart: unless-stopped
    depends_on:
      - gitlab-web
    volumes:
      - ./gitlab-runner/config/gitlab-runner:/etc/gitlab-runner
      - /var/run/docker.sock:/var/run/docker.sock
    networks:
      - gitlab-network

networks:
  gitlab-network:

Once it’s up and running, you can access GitLab via http://localhost/ by using username root and the password you’re asked to set when you first open the URL.

Then you need to set up GitLab Runner so that it would be able to execute pipelines. To do that, create a repository on your local GitLab (in my case, the repo was called cd), go to its CI/CD Settings, copy token (in my case it was: ta98ET_6ZD6YpC_ru3Sq). Then you need to add it to locally running GitLab Runner.

Simplest option would be to execute docker ps and I got the following response:

$ docker ps
CONTAINER ID        IMAGE                         COMMAND                  CREATED             STATUS                   PORTS                                             NAMES
7a490266683b        gitlab/gitlab-runner:alpine   "/usr/bin/dumb-init …"   5 minutes ago       Up 5 minutes                                                               cd_gitlab-runner_1
b46f3a6e6707        gitlab/gitlab-ce:latest       "/assets/wrapper"        5 minutes ago       Up 5 minutes (healthy)   0.0.0.0:22->22/tcp, 0.0.0.0:80->80/tcp, 443/tcp   cd_gitlab-web_1

So, then I copy GitLab Runner’s name (cd_gitlab-runner_1) and execute the following command:

docker exec -it cd_gitlab-runner_1 \
  gitlab-runner register \
    --non-interactive \
    --registration-token ta98ET_6ZD6YpC_ru3Sq \
    --locked=false \
    --description docker-stable \
    --url http://192.168.1.104\
    --executor docker \
    --docker-image docker:stable \
    --docker-volumes "/var/run/docker.sock:/var/run/docker.sock" \
    --docker-network-mode host

(instead of cd_gitlab-runner_1 and ta98ET_6ZD6YpC_ru3Sq use your tokens).

And you have a working local version(s) of GitLab and GitLab Runner.

Be First to Comment

Leave a Reply

Your email address will not be published.