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

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.

主站蜘蛛池模板: 巴林右旗| 逊克县| 汕头市| 香河县| 株洲县| 河西区| 栾城县| 杭锦后旗| 丰顺县| 古蔺县| 武宣县| 来宾市| 定南县| 古交市| 石屏县| 清新县| 明光市| 乌鲁木齐市| 杭锦旗| 岳池县| 襄垣县| 同德县| 高州市| 阳山县| 汉阴县| 即墨市| 宝坻区| 唐河县| 钟山县| 台北市| 竹溪县| 武威市| 平陆县| 兴国县| 南京市| 永康市| 封开县| 招远市| 涞水县| 鞍山市| 江西省|