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

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.

主站蜘蛛池模板: 南华县| 高平市| 余江县| 武城县| 乌兰察布市| 遵化市| 三门峡市| 原平市| 武陟县| 石棉县| 武山县| 南城县| 上林县| 江津市| 上林县| 宜宾市| 水富县| 阜城县| 长宁区| 五常市| 达尔| 甘谷县| 揭阳市| 临武县| 台南县| 资溪县| 修文县| 湟中县| 莱州市| 永城市| 肥乡县| 密云县| 辽宁省| 湖北省| 桐庐县| 红桥区| 增城市| 启东市| 津市市| 康乐县| 呼伦贝尔市|