docker 安装gitlab(ubuntu) gitlab-runner gitlab(windows)

一. gitlab

1.获取images

$ sudo docker pull gitlab/gitlab-ce

2.run

$ docker run -d  -p 443:443 -p 80:80 -p 2222:22 --name gitlab --restart always -v /home/gitlab/config:/etc/gitlab -v /home/gitlab/logs:/var/log/gitlab -v /home/gitlab/data:/var/opt/gitlab --privileged=true gitlab/gitlab-ce
# -d:后台运行
# -p:将容器内部端口向外映射  80:80而不用8080:80 因为gitlab的clone url中不带8080,所以gitlab_runner 配置url时找不到地址
# --name:命名容器名称
# -v:将容器内数据文件夹或者日志、配置等文件夹挂载到宿主机指定目录

3,配置

$ sudo vim /home/gitlab/data/gitlab-rails/etc/gitlab.yml

修改host为你服务的IP或者域名(不能加http://) ),修改完毕后保存退出
host:192.168.151.41
port:80




$ vim /home/gitlab/config/gitlab.rb

# 配置http协议所使用的访问地址,不加端口号默认为80
external_url 'http://192.168.151.41'

# 配置ssh协议所使用的访问地址和端口
gitlab_rails['gitlab_ssh_host'] = 'http://192.168.151.41'
gitlab_rails['gitlab_shell_ssh_port'] = '2222'

4.访问

http://192.168.151.41:2222

http://192.168.151.41:80  # gitlab

5.error

root@ubuntu-OptiPlex-380:/home/ubuntu/Desktop/testdjango# git push -u origin master


fatal: unable to access 'http://192.168.151.41/zyh/testdjango.git/': Failed to connect to 192.168.151.41 port 80: Connection refused


方案:git remote set-url origin http://192.168.151.41:8080/zyh/testdjango.git  

8080为docker外部映射端口

git remote -v

origin  http://192.168.151.41:8080/zyh/testdjango.git (fetch)
origin  http://192.168.151.41:8080/zyh/testdjango.git (push)

二.gitlab-runner

1.获取

$ docker run -d --name gitlab-runner --restart always -v /srv/gitlab-runner/config:/etc/gitlab-runner -v /var/run/docker.sock:/var/run/docker.sock gitlab/gitlab-runner:latest

2.进入

$  docker exec -it gitlab-runner bash

3.注册

首先到gitlab的项目下,进入setting->ci/cd Runner查看url与token


$ gitlab-runner register

$ url 

Please enter the gitlab-ci token 

$  token

Please enter the gitlab-ci description 

$ 描述

Please enter the gitlab-ci tags 

$ tag

Please enter the executor: ssh, docker+machine, docker-ssh+machine, kubernetes, docker, parallels, virtualbox, docker-ssh, shell:
docker

$ docker

如果上面执行者为docker,需要你在.gitlab-ci.yml中指定docker版本

Please enter the Docker image (eg. ruby:2.1):

$ alpine:latest

4.修改配置文件

$ vim /srv/gitlab-runner/config/config.toml

volumes配置,分别是挂载了宿主机的docker和配置Maven的缓存,提高效率

[[runners]]
  name = "dev_build_runner"
  url = "http://gitlab.XXX.top/"
  token = "9103bafa16b1f63232323434345"
  executor = "docker"
  [runners.docker]
    tls_verify = false
    image = "mvn-jdk:latest"
    privileged = false
    disable_cache = false
    volumes = ["/cache","/opt/data/gitlab-runner/.m2:/root/.m2"]
    pull_policy = "if-not-present"
    shm_size = 0
  [runners.cache]

修改如下

$ volumes = ["/cache", "/var/run/docker.sock:/var/run/docker.sock", "/data/.m2/:/.m2/"]

volumes配置下方增加一行配置,防止Runner重复拉取镜像

$ pull_policy = "if-not-present"

5.重启

$ docker restart gitlab-runner

3.SSH配置免密登录

$ sudo vim /etc/ssh/ssh_config

Host *
#   ForwardAgent no
#   ForwardX11 no
#   ForwardX11Trusted yes
#   PasswordAuthentication no
#   HostbasedAuthentication no
#   GSSAPIAuthentication no
#   GSSAPIDelegateCredentials no
#   GSSAPIKeyExchange no
#   GSSAPITrustDNS no
#   BatchMode no
#   CheckHostIP yes
#   AddressFamily any
#   ConnectTimeout 0
    StrictHostKeyChecking no   此处改为no
#   IdentityFile ~/.ssh/id_rsa
#   IdentityFile ~/.ssh/id_dsa
#   IdentityFile ~/.ssh/id_ecdsa
#   IdentityFile ~/.ssh/id_ed25519

三. gitlab(windows)

1.docker search gitlab
2.docker pull gitlab/gitlab-ce:latest
3.docker run -itd  -p 9080:9080 -p 9022:9022 -v C:/Users/kpqf626/Desktop/gitlab_mount/etc/gitlab:/etc/gitlab  -v C:/Users/kpqf626/Desktop/gitlab_mount/log/gitlab:/var/log/gitlab -v C:/Users/kpqf626/Desktop/gitlab_mount/opt:/var/opt/gitlab --restart always --privileged=true  --name gitlab1 gitlab/gitlab-ce
4.docker exec -it gitlab1 /bin/bash
5.vi /etc/gitlab/gitlab.rb
6.
# gitlab访问地址,可以写域名。如果端口不写的话默认为80端口 (图片上拼写错误,正确的是external_url)
external_url 'http://192.168.52.128:9080'
# ssh主机ip
gitlab_rails['gitlab_ssh_host'] = '192.168.52.128'
# ssh连接端口
gitlab_rails['gitlab_shell_ssh_port'] = 9022
7.vi /opt/gitlab/embedded/service/gitlab-rails/config/gitlab.yml
8.检查:
## GitLab settings
gitlab:
## Web server settings (note: host is the FQDN, do not include http://)
host: CNDCXD217703241
port: 8080
https: false 

9.gitlab-ctl reconfigure(修改gitlab.yml后不执行此步)
10.gitlab-ctl restart
11.修改root密码
docker-cli: gitlab-rails console -e production
 user=User.where(id:1).first
user.password='xx'
user.save()

你可能感兴趣的:(django,docker,gitlab)