6

Docker ドキュメントから:

Docker イメージは読み取り専用です。Docker がイメージからコンテナーを実行すると、アプリケーションが実行されるイメージの上に (UnionFS を使用して) 読み取り/書き込みレイヤーが追加されます。

変更はレイヤー間でどのように調整されますか? ファイルの内容を変更した場合、Docker はデルタのみを追跡しますか、それとも変更されたファイルを新しいレイヤーに保存しますか?

私はスーパーユーザーでこの議論を見ましたが、最終的な画像構造についてはまだ確信が持てません.

4

2 に答える 2

5

Every layer, of the image is RO except the top RW container layer and any volume mounts that are outside of the layered filesystem. If you download lots of files in the first layer, and delete them in the second layer (container running on top of the first layer), the second layer contains a delete command, but the files still exist in the first layer. You can see the results of this with docker diff:

$ docker run -it --name busytest busybox
/ # echo "hello world" >/root/test.txt
/ # rm /bin/rpm
/ # rm /bin/timeout
/ # rm /bin/wall
/ # exit

$ docker diff busytest
C /bin
D /bin/rpm
D /bin/timeout
D /bin/wall
C /root
A /root/.ash_history
A /root/test.txt

The diff is the contents of the RO layer of the container. And when you build an image, each RUN command generates a layer from this that is stored as part of your final image.

于 2016-10-21T16:50:54.310 に答える
2

レイヤー内にファイルがあり、それを (RUNまたはCOPYまたはを使用してADD) 変更すると、デルタではなく、新しいファイル全体で新しいレイヤーが作成されます。ファイルの権限属性のみを変更すると、さらに悪いことにRUN chmod 400 file、新しいレイヤーが作成され、ファイルの内容全体がこの新しいレイヤーに存在します。

よろしく

于 2016-10-21T17:01:12.767 に答える