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

Understanding temporary containers and image state

My website container has an ID that starts with 6e3d, which is the hostname that the application inside the container should see, but that's not what the website claims. So, what went wrong? Remember that Docker executes every build instruction inside a temporary, intermediate container.

The RUN instruction to generate the HTML ran in a temporary container, so the PowerShell script wrote that container's ID as the hostname in the HTML file; this is where the container ID starting with bf37 came from. The intermediate container gets removed by Docker, but the HTML file it created persists within the image.

This is an important concept: when you build a Docker image, the instructions execute inside temporary containers. The containers are removed, but the state they write persists within the final image and will be present in any containers you run from that image. If I run multiple containers from my website image, they will all show the same hostname from the HTML file, because that's saved inside the image, which is shared by all containers.

Of course, you can also store the state in individual containers, which is not part of the image, so it's not shared between containers. I'll look at how to work with data in Docker now and then finish the chapter with a real-world Dockerfile example.

主站蜘蛛池模板: 阳新县| 乌鲁木齐市| 新郑市| 都江堰市| 开原市| 大田县| 周宁县| 东丰县| 迁安市| 宝清县| 镶黄旗| 南部县| 留坝县| 武穴市| 霞浦县| 长阳| 和静县| 禹城市| 读书| 石屏县| 乃东县| 萝北县| 云南省| 安平县| 衡阳市| 金山区| 泗阳县| 万山特区| 盱眙县| 涞水县| 太湖县| 利川市| 富源县| 台北县| 巴马| 石景山区| 梨树县| 绥芬河市| 巫溪县| 易门县| 丁青县|