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

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.

主站蜘蛛池模板: 南木林县| 图片| 彭泽县| 阿勒泰市| 昌平区| 文山县| 石台县| 石景山区| 湖南省| 明溪县| 凉山| 祁东县| 富民县| 和硕县| 长兴县| 新郑市| 古蔺县| 开远市| 德格县| 左云县| 巴东县| 曲水县| 体育| 星座| 吴忠市| 芜湖市| 平遥县| 林西县| 武乡县| 大丰市| 平定县| 家居| 北川| 什邡市| 泉州市| 景东| 二手房| 许昌县| 靖江市| 乌拉特前旗| 旌德县|