官术网_书友最值得收藏!

Breaking the cache

In the container we just wrote, we somewhat glanced over the line RUN apt-get update -q && apt-get install -qy iputils-ping since it requires a bit of a deeper discussion here. In most Linux distributions, packages rotate in versions all the time, but the listing of these indexes that tell us where to find these is baked into the original Docker image when it gets created (ubuntu:latest in this case). Before we can install a package, in most cases, our index files have been stale for too long (if they haven't been completely removed), so we need to update them. Splitting this && joined line into two separate ones would work for that first build:

RUN apt-get update -q
RUN apt-get install -qy iputils-ping

But what happens when you add another package to that second line later, as shown in the following line?

RUN apt-get install -qy curl iputils-ping

In this case, Docker is not very smart and will consider the update line to be unchanged and will not run the update command again, so it will use the state from the cache for the update layer and then continue on to the next one that tries to install curl (since that one did change since the last build), which is likely to fail if enough versions have been rotated in the repositories as the indexes will be stale again. To prevent this from occurring, we join the update and the install commands with && so they are treated as one directive and create one layer, in which case, changing any part of either of the two joined commands will break the cache and run the update correctly. Sadly, as you get more involved with scalable Docker components, using odd tricks such as these to manage the cache and do selective cache busting will become a large part of your work.

主站蜘蛛池模板: 太湖县| 娱乐| 邻水| 吉林省| 白城市| 吉林市| 遵义市| 常宁市| 茂名市| 定日县| 莱州市| 和平区| 鹿邑县| 静乐县| 华阴市| 康平县| 沙雅县| 玉田县| 个旧市| 盘锦市| 大厂| 西乌珠穆沁旗| 堆龙德庆县| 湖州市| 宜阳县| 安岳县| 咸阳市| 泽州县| 富锦市| 光山县| 临颍县| 呈贡县| 沁源县| 五常市| 承德市| 凯里市| 沙坪坝区| 拉萨市| 恭城| 叶城县| 桃源县|