##概要
先日、下記のハンズオンに参加してきた。
Swiftコードを使ったWebアプリケーションの新しい開発方法 - Bluemix Swift runtime -
大体うまくいったんだけど、ターミナルでIBM CONTAINERS CF CLI PLUGINを使って、Bluemixにログインするところでこけてしまった!
結局ハンズオン中には解決しなかったので、悔しいから休日の数時間で四苦八苦しながら格闘。
そして、ログインして、ローカルのDockerイメージをBluemixのIBM CONTAINERS REGISTRYにプッシュして、アプリを実行するところまでこぎつけた。
その経緯を残しておこうと思って、書いた。
##環境
OS:Mac OS 10.10.5
Docker:Docker version 1.10.3, build 20f81dd
IBM CONTAINERS CF CLI PLUGIN:cf version 6.16.1+924508c-2016-02-26
※DockerとCF CLI PLUGINはHomebrewでインストール
##コマンドとエラーログ
問題のコマンドが下記。
cf ic login
出力されたエラーログ。
Deleting the old configuration file...
Retrieving client certificates from IBM Containers...
Storing client certificates in /Users/USER_NAME/.ice/certs/...
Storing client certificates in /Users/USER_NAME/.ice/certs/containers-api.ng.bluemix.net/4c65d548-19bf-4885-ae6f-b7e3b572d4cb...
OK
The client certificates were retrieved.
Checking local Docker configuration...
OK
Authenticating with the IBM Containers registry host registry.ng.bluemix.net...
FAILED
The attempt to authenticate with the IBM Containers registry host registry.ng.bluemix.net was unsuccessful.
**** exit status 1
****Error response from daemon: invalid registry endpoint https://registry.ng.bluemix.net/v0/: unable to ping registry endpoint https://registry.ng.bluemix.net/v0/
v2 ping attempt failed with error: Get https://registry.ng.bluemix.net/v2/: dial tcp: i/o timeout
v1 ping attempt failed with error: Get https://registry.ng.bluemix.net/v1/_ping: dial tcp: i/o timeout. If this private registry supports only HTTP or HTTPS with an unknown CA certificate, please add `--insecure-registry registry.ng.bluemix.net` to the daemon's arguments. In the case of HTTPS, if you have access to the registry's CA certificate, no need for the flag; simply place the CA certificate at /etc/docker/certs.d/registry.ng.bluemix.net/ca.crt
You can run only a limited number of IBM Containers commands.
ググりまくった結果、下記のサイトに辿り着いた。
ここでは回答者からDOCKER_CERT_PATHを設定するようにと書いてあった。
export DOCKER_CERT_PATH=/Users/your_username/.ice/certs
試しにDOCKER_CERT_PATHになにが設定してあるか確認。
echo $DOCKER_CERT_PATH
/Users/USER_NAME/.docker/machine/machines/dev
###もしやiceディレクトリの証明書が読み込めてなかった?
ということで、DOCKER_CERT_PATHを.iceに変更した
export DOCKER_CERT_PATH=/Users/USER_NAME/.ice
ログインしてみる。
cf ic login
Deleting the old configuration file...
Retrieving client certificates from IBM Containers...
Storing client certificates in /Users/USER_NAME/.ice/certs/...
Storing client certificates in /Users/USER_NAME/.ice/certs/containers-api.ng.bluemix.net/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx...
OK
The client certificates were retrieved.
Checking local Docker configuration...
You are authenticated with the IBM Containers API,
however, the local Docker daemon is not reachable to authenticate it
with the IBM Containers registry. You can still run IBM Containers
commands, but you cannot push or pull images until you start the local Docker daemon.
You can choose from two ways to use the Docker CLI with IBM Containers:
Option 1: This option allows you to use 'cf ic' for managing containers on IBM Containers while still using the Docker CLI directly to manage your local Docker host.
Use this Cloud Foundry IBM Containers plug-in without affecting the local Docker environment:
Example Usage:
cf ic ps
cf ic images
Option 2: Use the Docker CLI directly. In this shell, override the local Docker environment by setting these variables to connect to IBM Containers. Copy and paste the following commands:
Note: Only some Docker commands are supported with this option. Run cf ic help to see which commands are supported.
export DOCKER_HOST=tcp://containers-api.ng.bluemix.net:8443
export DOCKER_CERT_PATH=/Users/USER_NAME/.ice/certs/containers-api.ng.bluemix.net/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
export DOCKER_TLS_VERIFY=1
Example Usage:
docker ps
docker images
おお、なんかうまくいってるっぽい!
###勢いに任せてdocker pushしてみる
docker push プッシュするDockerイメージ
Could not read CA certificate "/Users/USER_NAME/.ice/ca.pem": open /Users/USER_NAME/.ice/ca.pem: no such file or directory
うわーん、またエラーだよ。。。
###困ったのでデフォルトのパスに戻す
eval "$(docker-machine env dev)"
###試しに再度ログインしてみる
cf ic login
Deleting the old configuration file...
Retrieving client certificates from IBM Containers...
Storing client certificates in /Users/USER_NAME/.ice/certs/...
Storing client certificates in /Users/USER_NAME/.ice/certs/containers-api.ng.bluemix.net/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx...
OK
The client certificates were retrieved.
Checking local Docker configuration...
OK
Authenticating with the IBM Containers registry host registry.ng.bluemix.net...
OK
You are authenticated with the IBM Containers registry.
Your organization's private Bluemix repository: registry.ng.bluemix.net/NAME_SPACE
You can choose from two ways to use the Docker CLI with IBM Containers:
Option 1: This option allows you to use 'cf ic' for managing containers on IBM Containers while still using the Docker CLI directly to manage your local Docker host.
Use this Cloud Foundry IBM Containers plug-in without affecting the local Docker environment:
Example Usage:
cf ic ps
cf ic images
Option 2: Use the Docker CLI directly. In this shell, override the local Docker environment by setting these variables to connect to IBM Containers. Copy and paste the following commands:
Note: Only some Docker commands are supported with this option. Run cf ic help to see which commands are supported.
export DOCKER_HOST=tcp://containers-api.ng.bluemix.net:8443
export DOCKER_CERT_PATH=/Users/USER_NAME/.ice/certs/containers-api.ng.bluemix.net/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
export DOCKER_TLS_VERIFY=1
Example Usage:
docker ps
docker images
よっしゃー!
よくわかんないけど、成功した!
docker push
も成功!
##まとめ
よくわかんないけど、できました(なんじゃそりゃ