2013-10-15 18 views
5

ドッカーAPI画像作成/プル(/v1.6/images/create)プロセスが成功または失敗の場合は明らかに常にドッカーAPI/images/createの処理方法は?

HTTP/1.1 200 OK 
Content-Type: application/json 

に関係なくを返します。

さらに、ペイロードは有効ではありませんjson。

例:/v1.6/images/create?fromImage=whatevertheflushは

リターン:

{"status":"Pulling repository whatevertheflush"}{"error":"Server error: 404 trying to fetch remote history for whatevertheflush","errorDetail":{"code":404,"message":"Server error: 404 trying to fetch remote history for whatevertheflush"}} 

有効なJSONされていない、と使用/転送されていないHTTPエラーが処理することが厄介になりクライアントのエラー。

確かに、ドッカー-pyはペイロード(https://github.com/dotcloud/docker-py/blob/master/docker/client.py#L374)をちょうど投げます。 openstackのDockerHTTPClientは、httpエラーコード(常に200)に基づいて値を返そうとします...(https://github.com/openstack/nova/blob/master/nova/virt/docker/client.py#L191

ここで、プルには長い時間がかかることがあります。クライアントへの回答をストリーミングしていますが、ここで何かが間違っていると考えるのを助けることはできません。

だから、これは3倍です:

  • 私は完全にここで何かが足りないのですか?
  • もしそうでなければ:クライアントアプリケーションを実装している場合(例えば、Pythonで)、どうすればこれを扱うことができますか?有効なjsonブロックを検出してロードし、何かが間違っていると「考える」たびに終了するようにしてください。
  • もしそうなら、これは今後のドッカーのバージョンで(これ以上)変更される予定ですか?

答えて

0

このエンドポイントは実際にはチャンクエンコードを返します。カール経由例:

$ curl -v -X POST http://localhost:4243/images/create?fromImage=base 
* About to connect() to localhost port 4243 (#0) 
* Trying ::1... 
* Connection refused 
* Trying 127.0.0.1... 
* connected 
* Connected to localhost (127.0.0.1) port 4243 (#0) 
> POST /images/create?fromImage=base HTTP/1.1 
> User-Agent: curl/7.24.0 (x86_64-apple-darwin12.0) libcurl/7.24.0 OpenSSL/0.9.8y zlib/1.2.5 
> Host: localhost:4243 
> Accept: */* 
> 
< HTTP/1.1 200 OK 
< Content-Type: application/json 
< Date: Fri, 07 Feb 2014 04:21:59 GMT 
< Transfer-Encoding: chunked 
< 
* Connection #0 to host localhost left intact 
{"status":"Pulling repository base"}{"status":"Pulling image (ubuntu-quantl) from  base","progressDetail":{},"id":"b750fe79269d"}{"status":"Pulling image (ubuntu-quantl) from base, endpoint: https://cdn-registry-1.docker.io/v1/","progressDetail":{},"id":"b750fe79269d"}{"status":"Pulling dependent layers","progressDetail":{},"id":"b750fe79269d"}{"status":"Download complete","progressDetail":{},"id":"27cf78414709"}{"status":"Download complete","progressDetail":{},"id":"b750fe79269d"}{"status":"Download complete","progressDetail":{},"id":"b750fe79269d"}* Closing connection #0 

今、私はあなたがPythonでこれを解析することについて行くかわからないんだけど、Rubyでは、私はそうのようなYajlを使用することができます。

ドッカーV1.9を使用して
parts = [] 
Yajl::Parser.parse(body) { |o| parts << o } 
puts parts 
{"status"=>"Pulling repository base"} 
{"status"=>"Pulling image (ubuntu-quantl) from base", "progressDetail"=>{}, "id"=>"b750fe79269d"} 
{"status"=>"Pulling image (ubuntu-quantl) from base, endpoint: https://cdn-registry-1.docker.io/v1/", "progressDetail"=>{}, "id"=>"b750fe79269d"} 
{"status"=>"Pulling dependent layers", "progressDetail"=>{}, "id"=>"b750fe79269d"} 
{"status"=>"Download complete", "progressDetail"=>{}, "id"=>"27cf78414709"} 
{"status"=>"Download complete", "progressDetail"=>{}, "id"=>"b750fe79269d"} 
{"status"=>"Download complete", "progressDetail"=>{}, "id"=>"b750fe79269d"} 
+0

まあ、それはそれはまた、JSONの塊だ、チャンクエンコーディングいないだけ - 確かに、私は終わったアップだけでなくPythonでパーサを書きます。しかし、答えをありがとう。 –

0

を私はまだこの問題に対処する必要があります。これは私のために働いていないapplication/json; boundary=NLDocker uses invalid JSON format in some API functions #16925

いくつかの要因は次のようにContent-Type HTTPヘッダーを使用することを提案: もドッカーのGithubリポジトリ上の問題を発見しました。

はその後、私のカスタムパーサーで苦労しながら、この質問のStackOverflowのを見つけました:How to handle a huge stream of JSON dictionaries?

0

次の手順では、ドッカーAPIを介してイメージを構築します。

サンプルDockerfile:

# cat Dockerfile 

FROM ubuntu:14.04 
RUN mkdir demo 
RUN apt-get update 
RUN apt-get -y install vim 

あなたDockerfileを含んでtarファイルを作成します。

# tar -cvf Dockerfile.tar.gz Dockerfile 

以下のようにAPIを実行し、その他のオプションについては、これを参照してください。

# curl -v -X POST -H "Content-Type:application/tar" --data-binary '@Dockerfile.tar.gz' http://127.0.0.1:5000/build?t=build_test 

# docker images 
REPOSITORY      TAG     IMAGE ID   CREATED    SIZE 
build_test      latest    b1736dd9b698  8 seconds ago 

はこれを参照してください:

how to configure docker daemon port

関連する問題