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

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.

主站蜘蛛池模板: 类乌齐县| 定陶县| 咸阳市| 汶上县| 皮山县| 安溪县| 吉隆县| 永顺县| 通渭县| 齐齐哈尔市| 沿河| 临西县| 卢龙县| 衡水市| 永登县| 鸡东县| 界首市| 万年县| 郯城县| 武强县| 昭苏县| 乌拉特后旗| 龙川县| 古蔺县| 鄂伦春自治旗| 巴青县| 奉新县| 绵竹市| 湛江市| 尚义县| 松桃| 汝城县| 塔河县| 大名县| 罗源县| 永康市| 民县| 梧州市| 南安市| 象山县| 丹阳市|