docker搭建gitlab-runner

使用docker容器技术部署gitlab runner

要使用docker-compose文件部署GitLab Runner,你可以按照以下步骤操作:

shell
复制代码
sudo mkdir -p /opt/store/gitlab-runner
  1. 创建docker-compose.yml文件: 创建一个名为docker-compose.yml的文件,并添加以下内容:

    yaml
    复制代码
    version: '3.8' services: gitlab-runner: image: registry.cn-hangzhou.aliyuncs.com/misaka-open/gitlab-runner:alpine3.18 container_name: "gitlab-runner" restart: always volumes: - '/opt/store/gitlab-runner:/etc/gitlab-runner' - '/var/run/docker.sock:/var/run/docker.sock' # 这个挂载是将宿主机上的docker socket挂载到了容器内,这样容器内执行的docker命令会被宿主机docker daemon最终执行

    在这个文件中,我们定义了一个名为gitlab-runner的服务,使用的是gitlab/gitlab-runner:latest镜像,并设置了卷挂载,以便GitLab Runner可以访问宿主机的Docker socket,从而能够执行Docker命令。

  2. 启动服务: 完成docker-compose.yml文件的编写后,使用以下命令来启动服务:

    shell
    复制代码
    docker-compose up -d
    image-20241220210654105.png

    这个命令将会启动GitLab Runner服务,并且以后台模式运行。你可以使用docker ps命令来验证服务是否已经成功启动。

  3. 注册GitLab Runner: 启动GitLab Runner容器后,你需要注册Runner。进入容器内部,执行注册命令:

    shell
    复制代码
    docker exec -it gitlab-runner gitlab-ci-multi-runner register

    按照提示输入GitLab实例的URL、注册token、Runner描述、标签等信息。对于执行器(executor),选择docker

    shell
    复制代码
    Enter the GitLab instance URL (for example, https://gitlab.com/): http://www.codefather.cn/ Enter the registration token: GR1348941yeBTxcSbQyCRywtspD-b Enter a description for the runner: [f20fce6332f4]: yupao-backend-runner Enter tags for the runner (comma-separated): build Enter optional maintenance note for the runner: Enter an executor: parallels, docker+machine, kubernetes, docker, docker-windows, docker-autoscaler, instance, custom, shell, ssh, virtualbox: docker Enter the default Docker image (for example, ruby:2.7): registry.cn-hangzhou.aliyuncs.com/acs/maven #这是配置了国内的中央仓库地址下载依赖比较快
    image-20241220211421165.png image-20241220211738334.png

以上步骤可以帮助你使用docker-compose文件部署GitLab Runner。确保你已经安装了Docker和Docker Compose,并且你的系统满足GitLab Runner的运行要求。

0个评论
点击登录,快来和大家讨论吧~
表情
图片
暂无评论
下载 APP