返回文章列表

CI 工具鏈 with Docker (1) — 安裝 Docker

2017-06-21
1 分鐘
DockerDevOpsCI

環境

  • Ubuntu Server 14.04 LTS

簡介

主要以 Docker 方式安裝以下服務:

  • DockerUI
  • GitLab
  • Jenkins

系列文章:

安裝 Docker

主要參考 Docker 官方網站的教學,使用 Ubuntu 14.04 的安裝方式:

$ sudo apt-get update
$ sudo apt-get install apt-transport-https ca-certificates
$ sudo apt-key adv --keyserver hkp://p80.pool.sks-keyservers.net:80 --recv-keys 58118E89F3A912897C070ADBF76221572C52609D

編輯 /etc/apt/sources.list.d/docker.list

/etc/apt/sources.list.d/docker.list 不存在就自己建立。打開後清空所有內容,加入以下這行:

deb https://apt.dockerproject.org/repo ubuntu-trusty main
$ sudo apt-get update

# Purge the old repo if it exists
$ sudo apt-get purge lxc-docker

$ apt-cache policy docker-engine
$ sudo apt-get install linux-image-extra-$(uname -r)
$ sudo apt-get install docker-engine
$ sudo service docker start

啟用 Docker Engine REST API

$ sudo vim /etc/init/docker.conf

找到如下區塊,把 DOCKER_OPTS= 改成:

script
        DOCKERD=/usr/bin/dockerd
        DOCKER_OPTS='-H tcp://0.0.0.0:2376 -H unix:///var/run/docker.sock'
        if [ -f /etc/default/$UPSTART_JOB ]; then
                . /etc/default/$UPSTART_JOB
        fi
        exec "$DOCKERD" $DOCKER_OPTS --raw-logs
end script

然後重開 Docker:

$ sudo service docker restart

安裝 Docker GUI 監控工具

$ sudo docker run -d -p 9090:9000 --privileged -v /var/run/docker.sock:/var/run/docker.sock --restart always uifd/ui-for-docker

用 Apache 保護 Docker GUI 監控工具

若無安全性疑慮可以跳過此步驟。

Step1. 安裝 Apache2 以及 proxy module

$ sudo apt-get update
$ sudo apt-get install apache2
$ sudo apt-get install -y build-essential
$ sudo apt-get install -y libapache2-mod-proxy-html libxml2-dev
$ sudo apt-get install apache2-utils

Step2. 啟用 proxy module

$ sudo a2enmod
# 系統接著會詢問你要啟用什麼 module,請輸入:
proxy proxy_ajp proxy_http rewrite deflate headers proxy_balancer proxy_connect proxy_html

Step3. 設定反向代理

$ sudo vim /etc/apache2/sites-enabled/000-default.conf

<VirtualHost *:80> 的區塊內,加入以下:

ProxyPreserveHost On
ProxyPass /docker-ui/ http://localhost:9090/
ProxyPassReverse /docker-ui/ http://localhost:9090/

Step4. 用密碼保護 GUI 介面

$ sudo mkdir /etc/htpasswd
$ sudo htpasswd -c /etc/htpasswd/.htpasswd [你設定的帳號]
# 此時會問密碼要設為什麼? 回答 [你設定的密碼]

再次編輯 Apache2 設定檔,在 <VirtualHost *:80> 的區塊之後加入:

<Location /docker-ui>
        AuthType Basic
        AuthName "Authentication Required"
        AuthUserFile "/etc/htpasswd/.htpasswd"
        Require valid-user

        Order allow,deny
        Allow from all
</Location>

Step5. 重新啟動 Apache2

$ sudo /etc/init.d/apache2 restart

Step7. 測試

由於已在路由器設定外網 80 port 指向 master 節點的 80 port(即剛安裝好的 Apache2),在外部瀏覽器輸入 http://[host-ip/domain]/docker-ui/ 後會被詢問密碼,通過後即可看到 Docker GUI 管理介面。

原文發表於 Medium

Command Palette

Search for a command to run...