项目
博客
文档
归档
资源链接
关于我
项目
博客
文档
归档
资源链接
关于我
Docker-compose部署Jenkins和Gitlab
2025-03-08
·
·
原创
·
docker
·
本文共 736个字,预计阅读需要 3分钟。
### CentOS7部署docker #### 更换镜像源 **备份当前的镜像源配置**: ```shell sudo mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.bak ``` **下载新的镜像源配置文件**: - **阿里云镜像源**: ```shell sudo curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo ``` - **清华大学镜像源** ```shell sudo curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.tuna.tsinghua.edu.cn/help/centos/ ``` **清理并更新缓存**: ```shell sudo yum clean all sudo yum makecache ``` #### 安装 **卸载旧版本的 Docker** ```shell sudo yum remove docker \ docker-client \ docker-client-latest \ docker-common \ docker-latest \ docker-latest-logrotate \ docker-logrotate \ docker-selinux \ docker-engine-selinux \ docker-engine ``` **添加 Docker 官方软件源** ```shell sudo yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo ``` **再次运行安装命令**: ```shell sudo yum install -y yum-utils device-mapper-persistent-data lvm2 ``` **安装** ```shell yum install -y docker-ce ``` **配置Docker信任地址** ```sh # 打开要修改的文件 vi /etc/docker/daemon.json # 添加内容: { "registry-mirrors": [ "https://05f073ad3c0010ea0f4bc00b7105ec20.mirror.swr.myhuaweicloud.com", "https://mirror.ccs.tencentyun.com", "https://0dj0t5fb.mirror.aliyuncs.com", "https://docker.mirrors.ustc.edu.cn", "https://6kx4zyno.mirror.aliyuncs.com", "https://registry.docker-cn.com", "https://akchsmlh.mirror.aliyuncs.com", "https://registry.docker-cn.com", "https://docker.mirrors.ustc.edu.cn", "https://hub-mirror.c.163.com", "https://docker.unsee.tech", "https://dockerpull.org", "http://docker.1panel.live", "https://dockerhub.icu" ] } # 重加载 systemctl daemon-reload # 重启 dockersystemctl restart docker ``` ### docker-compose安装 下载:https://github.com/docker/compose/releases,选择linux-x86_64 传到了/usr/local/bin/文件夹下,重命名:dockerc-compose 授权:sudo chmod +x /usr/local/bin/docker-compose 查询成功:docker-compose -v ### docker-compose安装Jenkins 构建docker-compose.yml文件 ```sh services: jenkins: image: jenkins/jenkins:latest # 使用 Jenkins 官方镜像 user: root # 以 root 用户运行 ports: - "8080:8080" # 映射端口 8080 - "50000:50000" # 映射端口 50000 volumes: - /app/tools:/app/tools # 宿主机安装的maven和git - /app/rep:/app/rep # 配置的maven仓库 - /etc/profile:/etc/profile # 配置的maven地址,Jenkins启动后需要在容器中执行sourece/etc/profile - /app/docker/jenkins/home:/var/jenkins_home # 挂载 Jenkins 数据目录 - /etc/localtime:/etc/localtime:ro # 挂载系统时间文件(只读) - /var/run/docker.sock:/var/run/docker.sock # 挂载 Docker 套接字 - /usr/bin/docker:/usr/bin/docker # 挂载 Docker 二进制文件 restart: always # 设置容器自动重启 ``` ### docker-compose安装gitlab 构建docker-compose.yml文件,启动`docker-compose up -d`,访问: http://192.168.60.123:8000 ```yaml services: gitlab: image: gitlab/gitlab-ce:latest # 使用最新版本的 GitLab 社区版 container_name: gitlab restart: always environment: TZ: 'Asia/Shanghai' # 设置时区 GITLAB_OMNIBUS_CONFIG: | external_url 'http://192.168.60.123:8000' # 使用 localhost 或 IP 地址 gitlab_rails['initial_root_password'] = '123456' # 设置初始管理员root账号密码 gitlab_rails['import_sources'] = ['github', 'gitea','bitbucket', 'gitlab', 'git'] # 邮件配置 gitlab_rails['smtp_enable'] = true gitlab_rails['smtp_address'] = "smtp.qq.com" # SMTP 服务器地址 gitlab_rails['smtp_port'] = 587 # SMTP 端口 gitlab_rails['smtp_user_name'] = "123456@qq.com" # SMTP 用户名 gitlab_rails['smtp_password'] = "cpsvjpmzdbozbdjg" # SMTP 密码 gitlab_rails['smtp_domain'] = "qq.com" # SMTP 域名 gitlab_rails['smtp_authentication'] = "login" # 认证方式 gitlab_rails['smtp_enable_starttls_auto'] = true # 是否启用 STARTTLS gitlab_rails['smtp_tls'] = false # 是否启用 TLS(如果需要) gitlab_rails['smtp_openssl_verify_mode'] = 'none' # SSL 验证模式 # 邮件发送配置 gitlab_rails['gitlab_email_from'] = '123456@qq.com' # 发件人邮箱 gitlab_rails['gitlab_email_display_name'] = 'GitLab' # 发件人显示名称 gitlab_rails['gitlab_email_reply_to'] = '123456@qq.com' # 回复地址 ports: - "8000:8000" # HTTP 端口 - "443:443" # HTTPS 端口(可选,如果不需要 HTTPS 可以移除) - "2222:22" # SSH 端口 volumes: - ./config:/etc/gitlab - ./logs:/var/log/gitlab - ./data:/var/opt/gitlab shm_size: '512m' ``` 本地安装git:https://blog.csdn.net/qq_25919879/article/details/128411860 安装maven: https://blog.csdn.net/weixin_48088839/article/details/132973700 配置仓库地址: | 仓库名称 | 阿里云仓库地址 | 阿里云仓库地址(老版) | 源地址 | | :--------------- | :--------------------------------------------------- | :----------------------------------------------------------- | :--------------------------------------- | | central | https://maven.aliyun.com/repository/central | https://maven.aliyun.com/nexus/content/repositories/central | https://repo1.maven.org/maven2/ | | public | https://maven.aliyun.com/repository/public | https://maven.aliyun.com/nexus/content/groups/public | central仓和jcenter仓的聚合仓 | | gradle-plugin | https://maven.aliyun.com/repository/gradle-plugin | https://maven.aliyun.com/nexus/content/repositories/gradle-plugin | https://plugins.gradle.org/m2/ | | apache snapshots | https://maven.aliyun.com/repository/apache-snapshots | https://maven.aliyun.com/nexus/content/repositories/apache-snapshots | https://repository.apache.org/snapshots/ | 查询java_home地址:readlink -f $(which java)