べにやまぶろぐ

技術寄りの話を書くつもり

docker build 時に出る 'Uploading context' とは何か?

バージョン : Docker 0.10.0

docker build をした際、

$ docker build -t hoge .
Uploading context 80MB

とか表示されて延々と何かをアップロードし始めて何事かと思ったんですが、Redirecting… によると

The path to the source repository defines where to find the context of the build. The build is run by the Docker daemon, not by the CLI, so the whole context must be transferred to the daemon. The Docker CLI reports "Uploading context" when the context is sent to the daemon.

とあり、まず docker build 時に指定されたパス(上記の例だとカレントディレクトリ)にあるファイル群を docker client から docker daemon に送ってそこでビルドできるようにするのが Uploading context とのこと (このとき、闇雲に全部送るのか ADD されているファイルだけ送るのかは不明 Redirecting… によれば "That means that all the files at PATH get sent, not just the ones listed to ADD in the Dockerfile." とのことで全ファイルが送られる。なので不要なファイルは極力置くべきではない。)

ポイントとしては docker build の処理自体は docker client ではなく docker daemon で行うということで、What is the meaning of "Uploading context" when executing ``docker build``? · Issue #2342 · moby/moby · GitHub

We are "uploading" the context from the docker client to the docker daemon, which again, might not even be running on the same host

とある通り docker client と docker daemon が別ホストで実行されているときは文字通りアップロードしてからビルドされるということです。これを同一ホスト内で実行すると ん、アップロードってどこに? となんかもやっと引っかかるわけですね。処理内容を理解するとわかるのですが。

ということでそれなら "Sending context to the docker daemon" というメッセージにしては?という意見が出ていました。

その後のコメントにもありますが実務で使おうかなというときにこういうメッセージが出ると一体何をどこに送っているのか不安になりますよね。Docker は用語の名前付けが結構わかりづらいというか不親切というかミスリードされやすいので 1.0 ではこの辺も改善されることを期待したいです。

全然関係ないですがスレッド内のやり取りにあった 'tarring' と 'compressing' は違う (tar はアーカイブ作るだけで圧縮とは別の話)って忘れてました。