docker安装Jenkins
- 拉取Jenkins基础镜像
docker pull jenkins/jenkins
- 编写dockerfile
USER root #清除了基础镜像设置的源,切换成腾讯云的jessie源 #使用非腾讯云环境的需要将 tencentyun 改为 aliyun RUN echo '' > /etc/apt/sources.list.d/jessie-backports.list \ && echo "deb http://mirrors.tencentyun.com/debian jessie main contrib non-free" > /etc/apt/sources.list \ && echo "deb http://mirrors.tencentyun.com/debian jessie-updates main contrib non-free" >> /etc/apt/sources.list \ && echo "deb http://mirrors.tencentyun.com/debian-security jessie/updates main contrib non-free" >> /etc/apt/sources.list #更新源并安装缺少的包 #RUN apt-get update && apt-get install -y libltdl7 && apt-get RUN apt-get update && apt-get update ARG dockerGid=999 RUN echo "docker:x:${dockerGid}:jenkins" >> /etc/group # 安装 docker-compose 因为等下构建环境的需要 RUN curl -L https://github.com/docker/compose/releases/download/1.16.1/docker-compose-`uname -s`-`uname -m` -o /usr/local/bin/docker-compose RUN chmod +x /usr/local/bin/docker-compose
- 创建docker容器映射的文件
mkdir -p /var/jenkins_home chown -R 1000 /var/jenkins_home
- build镜像
docker build -t auto-jenkins:v1 .
- 启动Jenkins
docker run --name jenkins -p 8081:8080 -p 50000:50000 -v /var/run/docker.sock:/var/run/docker.sock -v $(which docker):/bin/docker -v /var/jenkins_home:/var/jenkins_home -d auto-jenkins:v1
- 进入Jenkins容器查看密码
docker ps 可以查看容器ID docker exec -it xxx(容器ID) /bin/bash # 查看Jenkins的初始密码 cat /var/jenkins_home/secrets/initialAdminPassword
- 访问Jenkins即可 127.0.0.1:8081
docker安装gitlab
- 拉取gitlab镜像
docker pull gitlab/gitlab-ce:latest
- 创建gitlab容器映射文件夹
mkdir -p /home/gitlab/config mkdir -p /home/gitlab/data mkdir -p /home/gitlab/logs
- 启动容器
docker run --detach --hostname 192.168.10.229(填写本机地址) --publish 7001:443 --publish 7002:80 --publish 7003:22 --name gitlab --restart always --volume /home/gitlab/config:/etc/gitlab --volume /home/gitlab/logs:/var/log/gitlab --volume /home/gitlab/data:/var/opt/gitlab
- 修该文件
vim /home/gitlab/config/gitlab.rb # 添加: external_url 'http://192.168.192.38' # (本机地址) gitlab_rails['gitlab_ssh_host'] = '192.168.192.38' # (本机地址) gitlab_rails['gitlab_shell_ssh_port'] = 7003 # (端口)
- 进入容器重置配置
docker ps #(可以查看容器ID) docker exec -it xxx(容器ID) /bin/bash # 执行命令 gitlab-ctl reconfigure # 等待然后重启 docker restart xxx #(容器ID)
- 获取gitlab root账户密码
# 进入容器ID docker exec -it xxx(容器ID) /bin/bash # 获取密码 cat /etc/gitlab/initial_root_password
- 访问gitlab
http://127.0.0.1:7002 或 http://127.0.0.1:7003