Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
[Docker] Private Registry
published tags
true
Docker

[Docker] Private Registry

這篇同步發佈在我的BlogGist

前言

最近開始run startup,非常忙碌,沒什麼時間寫blog,但是有些難找的東西,還是要記錄一下,看看能不能幫到別人。

之前主要專注在backend,現在自己要負責所有技術的東西,最近一直在看front-end的新技術,真的多到看不完耶,除了dev,ops的東西也要一併處理,所以就有這篇文章的出現…

不熟Docker的朋友們,請先閱讀這篇Docker -- 從入門到實踐

Docker這麼紅、這麼方便,一定要用的啊!但除了用Docker Hub(公共repostiry)上了image,我自己寫開發的app,不可能放出去,所以會要架自己的Docker Registry來放,以方便內部佈置與自動化機制的建置。

背景

以下是我的環境 Docker Registry: Synology DS415+ with latest docker-registry version Docker Client: Mac OSX 10.11.1 with Docker 1.8.3 Docker Publish Env: SBT Native Packager

Private Docker Registry

安裝Private Docker Registry很簡單,官方就有registry的image,直接抓下來用就行! 網路上也有很多文章教你怎麼用,這裡就不多說了。

但我遇到的問題就是,預設Docker Registry是"安全的",也就是他會要求你走TLS,這樣對於沒有certificate的使用者,就無法用了。

我試著要從sbt-native-packager使用docker:publish的時候,發生了下面的錯誤,一度以為是我的Registry沒灌好…

[error] unable to ping registry endpoint https://192.168.1.2:6000/v0/
[error] v2 ping attempt failed with error: Get https://192.168.1.2:6000/v2/: EOF
[error]  v1 ping attempt failed with error: Get https://192.168.1.2:6000/v1/_ping: EOF
[trace] Stack trace suppressed: run last docker:publish for the full output.
[error] (docker:publish) Nonzero exit value: 1
[error] Total time: 9 s, completed Nov 6, 2015 7:59:57 PM

但是後來眼尖的發現,他連的是https

Insecure Registry

那我們就讓他"不安全"吧!

官方有寫這篇Insecure Registry,提到兩個方式:

  1. 直接用 DOCKER_OPTS="--insecure-registry myregistrydomain.com:5000" 告訴你的docker daemon不要去檢查registry的安全性,好處是很簡單的設定,壞處是非常不安全,而且你要設定每一個docker daemon (就是每一台要連registry的機器都要設)。
  2. 使用自己簽的certificate。這個東西有點複雜,下次再來研究。

ps: 本來嘗試要從sbt-native-package下手,但官方說法是這應該要從docker daemon下手,他們也無能為力。,

動手做

這邊我要做的是#1的solution,但是發現在Mac上好像跟官方說的方式不太一樣,後來查了這篇,才找到這個方法來解決。

修改Mac內的docker-machine

Joes-MBP:admin-backend-api joecwu$ docker-machine ssh default
                        ##         .
                  ## ## ##        ==
               ## ## ## ## ##    ===
           /"""""""""""""""""\___/ ===
      ~~~ {~~ ~~~~ ~~~ ~~~~ ~~~ ~ /  ===- ~~~
           \______ o           __/
             \    \         __/
              \____\_______/
 _                 _   ____     _            _
| |__   ___   ___ | |_|___ \ __| | ___   ___| | _____ _ __
| '_ \ / _ \ / _ \| __| __) / _` |/ _ \ / __| |/ / _ \ '__|
| |_) | (_) | (_) | |_ / __/ (_| | (_) | (__|   <  __/ |
|_.__/ \___/ \___/ \__|_____\__,_|\___/ \___|_|\_\___|_|
Boot2Docker version 1.8.3, build master : af8b089 - Mon Oct 12 18:56:54 UTC 2015
Docker version 1.8.3, build f4bf5c7
docker@default:~$ sudo vi /var/lib/boot2docker/profile

/var/lib/boot2docker/profile 內,增加一行 --insecure-registry 192.168.1.2:6000

EXTRA_ARGS='
--label provider=virtualbox
--insecure-registry 192.168.1.2:6000
'
CACERT=/var/lib/boot2docker/ca.pem
DOCKER_HOST='-H tcp://0.0.0.0:2376'
DOCKER_STORAGE=aufs
DOCKER_TLS=auto
SERVERKEY=/var/lib/boot2docker/server-key.pem
SERVERCERT=/var/lib/boot2docker/server.pem

重新啟動docker-machine

Joes-MBP:admin-backend-api joecwu$ docker-machine stop default
Joes-MBP:admin-backend-api joecwu$ docker-machine start default
Starting VM...
Started machines may have new IP addresses. You may need to re-run the `docker-machine env` command.

Result

Run docker:publish

> docker:publish
[info] Wrote ........./admin-backend-api_2.11-0.1.0.pom
[info] Sending build context to Docker daemon 557.1 kB
[info] Sending build context to Docker daemon 1.114 MB
[info] Step 7 : CMD
[info]  ---> Using cache
[info]  ---> 48923d750c11
[info] Successfully built 48923d750c11
[info] Built image 192.168.1.2:6000/kiri/admin-backend-api:0.1.0
[info] The push refers to a repository [192.168.1.2:6000/kiri/admin-backend-api] (len: 1)
[info] Sending image list
[info] Pushing repository 192.168.1.2:6000/kiri/admin-backend-api (1 tags)
...
[info] 48923d750c11: Pushing
[info] 48923d750c11: Image successfully pushed
[info] Pushing tag for rev [48923d750c11] on {http://192.168.1.2:6000/v1/repositories/kiri/admin-backend-api/tags/0.1.0}
[info] Published image 192.168.1.2:6000/kiri/admin-backend-api:0.1.0
Joes-MacBook-Pro:~ joecwu$ curl -i http://192.168.1.2:6000/v1/search
HTTP/1.1 200 OK
Server: gunicorn/19.1.1
Date: Sat, 07 Nov 2015 08:51:54 GMT
Connection: keep-alive
Expires: -1
Content-Type: application/json
Pragma: no-cache
Cache-Control: no-cache
Content-Length: 99

{"num_results": 1, "query": "", "results": [{"description": "", "name": "kiri/admin-backend-api"}]}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment