Docker Compose yml for Gitlab and Gitlab Runner

Docker Compose yml for Gitlab and Gitlab Runner

Get Social!
version: '3.5'
services:
  gitlab:
    image: gitlab/gitlab-ce:latest
    hostname: www.jamescoyle.net
    restart: unless-stopped
    environment:
      GITLAB_OMNIBUS_CONFIG: |
        gitlab_rails['gitlab_shell_ssh_port'] = 8822
    ports:
      - "8000:80"
      - "8822:22"
    volumes:
      - ./config/gitlab:/etc/gitlab
      - ./data/gitlab:/var/opt/gitlab
      - ./logs:/var/log/gitlab
    networks:
      - gitlab

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

networks:
  gitlab:

Create a new directory and save the above file inside it as docker-compose.yml. You’ll need to replace the field hostname with the external URL that you’ll use to access your Gitlab instance.

mkdir gitlab
vi gitlab\docker-compose.yml

Run docker-compose up -d to fetch the images from the docker hub and create your Gitlab instance. You’ll be able to access Gitlab from a browser on port 8000 and the SSH on port 8822.


14 Comments

Brian Riggs

28-Oct-2019 at 7:30 pm

Very helpful, but how do I get the runner to register with the gitlab server?
For example, I run “docker exec -it gitlab-runner bash” and then run “gitlab-runner register” within the runner container, however, it cannot resolve the gitlab hostname that I specified in the docker-compose.yml file.

Vilda

31-Oct-2019 at 3:59 pm

You have a mistake/typo in port section. – “8822:8822” should be – “8822:22” you want the external set in ‘gitlab_shell_ssh_port’ still point to 22

    James Coyle

    1-Nov-2019 at 9:15 am

    Thanks.

Jèr Nersa

27-May-2020 at 9:35 pm

How does gitlab know about the runner? Don’t you need to specify the gitlab url to the gitlab runner?

    narsi

    19-May-2021 at 3:51 am

    I think it is linked via depends_on

hung

9-Jun-2020 at 4:57 pm

Did you test on the Windows?
version: ‘3.5’
services:
gitlab:
image: gitlab/gitlab-ce:latest
hostname: http://www.jamescoyle.net
restart: unless-stopped
environment:
GITLAB_OMNIBUS_CONFIG: |
gitlab_rails[‘gitlab_shell_ssh_port’] = 8822
ports:
– “8000:80”
– “8822:22”
volumes:
– E:/1/1/config:/etc/gitlab
– E:/1/1/data:/var/opt/gitlab
– E:/1/1/logs:/var/log/gitlab
networks:
– gitlab

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

networks:
gitlab:
it does not work
———————
but when i comment out the volume, it works fine.

version: ‘3.5’
services:
gitlab:
image: gitlab/gitlab-ce:latest
hostname: http://www.jamescoyle.net
restart: unless-stopped
environment:
GITLAB_OMNIBUS_CONFIG: |
gitlab_rails[‘gitlab_shell_ssh_port’] = 8822
ports:
– “8000:80”
– “8822:22”

networks:
– gitlab

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

networks:
gitlab:

    Dmitiry

    18-Aug-2020 at 9:38 am

    there is a problem with postgres, when you run on windows. you can try to mount volume instead of folder for /var/opt/gitlab

hung

11-Oct-2020 at 3:11 am

on the ubuntu do not run too

david king

19-Nov-2020 at 5:53 am

why docker-compose up run docker container failed?

ERROR: Failed to load config stat /etc/gitlab-runner/config.toml: no such file or directory builds=0

    Igor

    29-Sep-2022 at 6:43 pm

    This is a issue. The gitlab-runner need a file called config.toml, and he can.t create it. I figure it out creating this file with permissions ( ch mod 777 ) inside the volume data/gitlab-runner/config:/etc/gitlab-runner after the container is running.

david king

19-Nov-2020 at 5:58 am

# sudo docker-compose -p gitlab -f docker-compose-gitlab.yml up

version: “3.6”
services:
gitlab-server:
image: gitlab/gitlab-ce:latest
container_name: gitlab-server
hostname: gitlab.local.net
restart: always
environment:
GITLAB_OMNIBUS_CONFIG: |
external_url ‘http://gitlab.local.net’
gitlab_rails[‘gitlab_shell_ssh_port’] = 23
ports:
– “9080:80”
– “23:22”
volumes:
– /data/gitlab-server/config:/etc/gitlab
– /data/gitlab-server/data:/var/opt/gitlab
– /data/gitlab-server/logs:/var/log/gitlab
– /etc/localtime:/etc/localtime
networks:
– gitlab

gitlab-runner:
image: gitlab/gitlab-runner:latest
container_name: gitlab-runner
restart: always
privileged: true
depends_on:
– gitlab-server
volumes:
– /data/gitlab-runner/config:/etc/gitlab-runner
– /data/gitlab-runner/run/docker.sock:/var/run/docker.sock
networks:
– gitlab

networks:
gitlab:

why docker compose up run docker container failed.

ERROR: Failed to load config stat /etc/gitlab-runner/config.toml: no such file or directory builds=0

CM

8-Feb-2021 at 12:18 pm

Hy,

do you lose any data if the docker host restarts?
There are some volumes specified, so in theory no data should be lost.

S

3-Jul-2022 at 5:35 pm

Hello,
Thx for this docker-compose
But after docker-compose up there’s this error message:
gitlab-runner_1 | ERROR: Failed to load config stat /etc/gitlab-runner/config.toml: no such file or directory builds=0

Is not config.toml created after et gitlab-runner register ?
How to execute this docker-compose from scratch ?
Thank you for your help

LM

9-Aug-2022 at 7:16 pm

gitlab runner is failing upon registering pls help

Leave a Reply

Visit our advertisers

Quick Poll

Do you use ZFS on Linux?

Visit our advertisers