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

  • Docker on Windows
  • Elton Stoneman
  • 213字
  • 2021-07-02 19:53:20

Understanding temporary containers and image state

My website container has an ID that starts 3472, which is the hostname 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. The intermediate container gets removed by Docker, but the HTML file it created is persisted in 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 is persisted in 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 store 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.

主站蜘蛛池模板: 香河县| 新泰市| 绥芬河市| 巴中市| 利津县| 融水| 华宁县| 内江市| 原平市| 南宁市| 永吉县| 永清县| 洛阳市| 天柱县| 霍林郭勒市| 喀什市| 灌南县| 喀什市| 台东县| 米泉市| 化德县| 嘉定区| 临邑县| 南丹县| 永平县| 卢湾区| 仙居县| 永修县| 五华县| 揭东县| 三门峡市| 仁寿县| 天峨县| 无棣县| 淮北市| 台东市| 绥阳县| 兰考县| 北宁市| 申扎县| 灵丘县|