docker-compose部署gitlab和jenkins

通过docker-compose部署gitlab和jenkins,方便后续工作

注意:

  1. gitlab占用资源较多,最好系统内存在8G以上,CPU4核心以上,否则gitlab有可能报错无法启动。
  2. docker版本用最新版本,低版本的docker可能会导致docker-compose部署的容器网络无法互通,在配置jenkins和gitlab时会出现 no route, no host等错误提示。

安装docker和docker-compose

略过不表,若有需要可以文章下留言,有时间在写

创建必要目录

mkdir /home/docker
cd /home/docker
mkdir jenkins gitlab
chown -R 1000:1000 jenkins

启动容器

复制一下内容保存为docker-compose.yml, 运行docker-compose up -d,时间比较久,耐心等待,完成启动后运行docker-compose ps查看容器运行状态,若都是running状态,则表示正常启动

version: "3.8"
services:
  gitlab:
    restart: always
    privileged: true
    tty: true
    container_name: gitlab
    image: gitlab/gitlab-ce  #选择gitlab社区版本
    ports:
      - "80:80"
      - "8022:22"
    volumes:
      - ./gitlab/etc:/etc/gitlab
      - ./gitlab/log:/var/log/gitlab
      - ./gitlab/opt:/var/opt/gitlab
    environment:
      GITLAB_OMNIBUS_CONFIG: |
        external_url 'http://ip:port'  #ip为本机ip,port为80映射的端口
        gitlab_rails['gitlab_shell_ssh_port'] = sshport #sshport为22映射的端口
        gitlab_rails['time_zone'] = 'Asia/Shanghai' #时区
        gitlab_rails['smtp_enable'] = true  #弃用邮件功能
        gitlab_rails['smtp_address'] = "smtp.qq.com"  # qq邮箱的smtp地址
        gitlab_rails['smtp_port'] = 587  #qq邮箱的smtp端口
        gitlab_rails['smtp_user_name'] = ""  #输入自己的qq邮箱
        gitlab_rails['smtp_password'] = ""  #qq邮箱的授权码
        gitlab_rails['smtp_domain'] = "smtp.qq.com"
        gitlab_rails['smtp_authentication'] = "login"
        gitlab_rails['smtp_enable_starttls_auto'] = true
        gitlab_rails['smtp_tls'] = false
        gitlab_rails['smtp_pool'] = false
        gitlab_rails['gitlab_email_enabled'] = true
        gitlab_rails['gitlab_email_from'] = ''  #输入自己的qq邮箱
        gitlab_rails['gitlab_email_reply_to'] = ''  #输入自己的qq邮箱
        gitlab_rails['manage_backup_path'] = true   #开启备份功能
        gitlab_rails['backup_archive_permissions'] = 0644
        gitlab_rails['backup_keep_time'] = 604800   #日志时长/秒
        alertmanager['admin_email'] = '' #告警提醒地址,输入自己的qq邮箱
      
  jenkins:
    restart: always
    privileged: true
    tty: true
    container_name: jenkins
    image: jenkins/jenkins:lts-jdk17
    ports:
      - "8080:8080"
      - "50000:50000"
    volumes:
      - ./jenkins:/var/jenkins_home:rw
      - /var/run/docker.sock:/var/run/docker.sock
      - /etc/docker:/etc/docker
      - /usr/bin/docker:/usr/bin/docker
      - /etc/localtime:/etc/localtime:ro
    environment:
      TZ: Asia/Shanghai

看到这里了,点个赞在走吧。

你可能感兴趣的:(docker,gitlab,jenkins,docker-compose)