docker下運行Gitlab CE+Jenkins+Nexus3+docker-registry-frontend

DevOps
- Gitlab CE
- Jenkins
- Nexus


Gitlab CE
https://hub.docker.com/r/gitlab/gitlab-ce/
https://docs.gitlab.com/omnibus/docker/README.html
$ docker pull gitlab/gitlab-ce

sudo docker run --detach \
    --hostname gitlab.example.com \
    --publish 443:443 --publish 80:80 --publish 22:22 \
    --name gitlab \
    --restart always \
    --volume /srv/gitlab/config:/etc/gitlab \
    --volume /srv/gitlab/logs:/var/log/gitlab \
    --volume /srv/gitlab/data:/var/opt/gitlab \
    gitlab/gitlab-ce:latest

或者(啓用SELinux的狀況)

sudo docker run --detach \
    --hostname gitlab.example.com \
    --publish 443:443 --publish 80:80 --publish 22:22 \
    --name gitlab \
    --restart always \
    --volume /srv/gitlab/config:/etc/gitlab:Z \
    --volume /srv/gitlab/logs:/var/log/gitlab:Z \
    --volume /srv/gitlab/data:/var/opt/gitlab:Z \
    gitlab/gitlab-ce:latest

Local location       Container location  Usage
/srv/gitlab/data     /var/opt/gitlab     For storing application data
/srv/gitlab/logs     /var/log/gitlab     For storing logs
/srv/gitlab/config   /etc/gitlab         For storing the GitLab configuration files

其中gitlab.example.com(可沒必要)替換成本身的服務器域名或者ip地址,首次運行,數據庫資料、文件連接等都會自動被建立,用logs查看狀況:
$ sudo docker logs gitlab -f

配置文件:/etc/gitlab/gitlab.rb
能夠用exec -it去編輯:
$ sudo docker exec -it gitlab vi /etc/gitlab/gitlab.rb

配置後,用restart重啓
$ sudo docker restart gitlab

關於配置文件:
external_url    若是是https,可配置下,由於是在容器中,默認的80端口不須要修改。
https、SMTP詳細配置:
https://docs.gitlab.com/omnibus/settings/nginx.html#enable-https
https://docs.gitlab.com/omnibus/settings/smtp.html


Jenkins
https://hub.docker.com/r/jenkinsci/blueocean/
https://jenkins.io/doc/book/installing/#docker
$ docker pull jenkinsci/blueocean

docker run \
  -d \
  -p 8080:8080 \
  -v jenkins-data:/var/jenkins_home \
  -v /var/run/docker.sock:/var/run/docker.sock \
  --name jenkins \
  --restart always \
  jenkinsci/blueocean

官方版本:
docker run \
  -u root \
  --rm \
  -d \
  -p 8080:8080 \
  -p 50000:50000 \
  -v jenkins-data:/var/jenkins_home \
  -v /var/run/docker.sock:/var/run/docker.sock \
  jenkinsci/blueocean
詳細介紹見前面的#docker連接

運行後,經過 docker logs jenkins -f 能看到初始管理員密碼,若是沒看見,能夠用下面命令查看:
$ docker exec -it jenkins cat /var/jenkins_home/secrets/initialAdminPassword
打開瀏覽器,輸入初始密碼,進入安裝嚮導,按提示配置便可。

經常使用插件:(**開頭的應該是自帶的,*爲其餘)
Ansible pllugin
AnsiColor
Artifactory Plugin
**Blue Ocean
Consul Plugin
Delivery Pipeline Plugin
Docker plugin
GitLab Plugin
Marathon Deployment
Maven Dependency Update Trigger
Maven Info Plugin
Maven Metadata Plugin for Jenkins CI server
Maven Release Plug-in Plug-in
Maven Repository Server Plugin
MSBuild Plugin
NodeJS Plugin
packer
Parameterized Scheduler
Pipeline Maven Integration Plugin
Pipeline NPM Integration Plugin
SSH Agent Plugin
Terraform Plugin
**Timestamper
Unleash Maven Plugin
*Gogs plugin


Nexus
https://hub.docker.com/r/sonatype/nexus3/
https://github.com/sonatype/docker-nexus3
https://www.sonatype.com/download-oss-sonatype
支持: Bower  Docker  Git LFS  Maven  npm  NuGet  PyPI  Ruby Gems  Yum Proxy
$ docker pull sonatype/nexus3
映射卷注意:由於nexus-data要求UID 200,下面是建立一個nexus-data卷後,用inspect命令查看路徑,
而後手動設置本機實際路徑全部者爲UID 200後,再調用run命令,不然會啓動失敗。
docker volume create --name nexus-data
docker volume inspect nexus-data
sudo chown -R 200 /var/lib/docker/volumes/nexus-data/_data
docker run -d -p 8081:8081 -v nexus-data:/nexus-data --restart always --name nexus sonatype/nexus3
若是將配置Docker倉庫在5001,還有加入 -p 5001:5001,以下:
docker run -d -p 8081:8081 -p 5001:5001 -v nexus-data:/nexus-data --restart always --name nexus sonatype/nexus3
其餘類同。

用 docker logs -f nexus 查看啓動日誌。

測試釋放成功:curl -u admin:admin123 http://localhost:8081/service/metrics/ping
更詳細見:https://hub.docker.com/u/sonatype/
Default credentials are: admin / admin123




-----------------
Docker Hub(私有)
-----------------
官方:https://hub.docker.com/_/registry/
參考:https://docs.docker.com/registry/deploying/
$ docker run -d -p 5000:5000 --restart=always --name registry registry

查看有幾個倉庫
http://RegistryServer:5000/v2/_catalog
查看某個倉庫的tags
http://RegistryServer:5000/v2/RegistryName/tags/list

存儲選項(-v 宿主機全路徑:容器全路徑[:ro|rw],在類UNIX系統中`pwd`返回當前目錄)
-v `pwd`/data:/var/lib/registry
這行意思是將當前目錄下的data目錄,做爲容器/var/lib/registry的映射目錄。
注意:Windows系統,路徑要用/代替\,而且在Docker配置Shared Drivers裏開啓了對應盤符的共享。

假設私有Docker Hub主機名是RegistryServer,固然IP也能夠,用tag命令打一個新標籤,而後用push推送到服務器:
$ docker tag m2nlight/static_web RegistryServer:5000/m2nlight/static_web
$ docker images
$ docker push RegistryServer:5000/m2nlight/static_web
若是push失敗:
Get https://RegistryServer:5000/v1/_ping: http: server gave HTTP response to HTTPS client
須要在客戶機的Docker加入對服務器的信任配置:
mac: 進入Docker配置的Advanced頁,在Insecure registries列表里加入如:RegistryServer:5000
win: 進入Docker設置的Docker Daemon選項,在右邊的json格式文本框的insecure-registries後加入:RegistryServer:5000
linux: $ vim /etc/docker/daemon.json
{
  "insecure-registries": ["RegistryServer:5000"]
}
$ systemctl restart docker
重啓客戶機Docker生效。

被tag的「鏡像」,一樣適用其餘鏡像操做,好比rmi「刪除」。


-----------------
Registry Frontend
-----------------
https://hub.docker.com/r/konradkleine/docker-registry-frontend/
https://github.com/kwk/docker-registry-frontend
$ konradkleine/docker-registry-frontend:v2
注意:v2是最新版本。

sudo docker run \
  -d \
  -e ENV_DOCKER_REGISTRY_HOST=192.168.48.10 \
  -e ENV_DOCKER_REGISTRY_PORT=5000 \
  -e ENV_MODE_BROWSE_ONLY=true \
  -p 8080:80 \
  --restart=always \
  --name=registry-frontend \
  konradkleine/docker-registry-frontend:v2

更多參數:
(1)Docker registry using SSL encryption
 -e ENV_DOCKER_REGISTRY_USE_SSL=1
(2)SSL encryption
 -e ENV_USE_SSL=yes \
 -v $PWD/server.crt:/etc/apache2/server.crt:ro \
 -v $PWD/server.key:/etc/apache2/server.key:ro \
 -p 443:443 \
(3)Use the application as the registry
 -e ENV_REGISTRY_PROXY_FQDN=ENTER-YOUR-APPLICATION-HOST-HERE \
 -e ENV_REGISTRY_PROXY_PORT=ENTER-PORT-TO-YOUR-APPLICATION-HOST-HERE \
 -e ENV_USE_SSL=yes \
 -v $PWD/server.crt:/etc/apache2/server.crt:ro \
 -v $PWD/server.key:/etc/apache2/server.key:ro \
 -p 443:443 \
 (4)其餘
 -e ENV_MODE_BROWSE_ONLY=true
 -e ENV_DEFAULT_REPOSITORIES_PER_PAGE=50
 更多見 https://hub.docker.com/r/konradkleine/docker-registry-frontend/
相關文章
相關標籤/搜索