如何在Docker中保存中间容器?

如何在Docker中保存中间容器?,docker,Docker,我正在从Dockerfile构建一个多步骤映像,但目前有一个步骤失败。我想做的是运行interactive中的最后一个成功步骤并对其进行调试 不幸的是,Docker删除了中间容器: Removing intermediate container dac6772bcf71 ---> aa6de00f27db 所以我不能做: docker run -it dac6772bcf71 /bin/bash 我找到了--force rm选项,但没有找到keep intermediate选项 如何

我正在从Dockerfile构建一个多步骤映像,但目前有一个步骤失败。我想做的是运行interactive中的最后一个成功步骤并对其进行调试

不幸的是,Docker删除了中间容器:

Removing intermediate container dac6772bcf71
 ---> aa6de00f27db
所以我不能做:

docker run -it dac6772bcf71 /bin/bash
我找到了
--force rm
选项,但没有找到
keep intermediate
选项

如何让Docker保留中间容器

具体例子

伊尔,我有这个:

Removing intermediate container dac6772bcf71
 ---> aa6de00f27db
Step 9/9 : RUN pip install git+https://github.com/heig-vd-tin/sphinx-heigvd-theme.git
 ---> Running in a4745435a814
Collecting git+https://github.com/heig-vd-tin/sphinx-heigvd-theme.git
  Cloning https://github.com/heig-vd-tin/sphinx-heigvd-theme.git to /tmp/pip-req-build-AKf_Kz
    Complete output from command python setup.py egg_info:
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "/tmp/pip-req-build-AKf_Kz/setup.py", line 2, in <module>
        import sphinx_heigvd_theme
      File "sphinx_heigvd_theme/__init__.py", line 141
        toc_href = f'{relative_uri(baseuri, toc_uri)}#{anchor_id}'

但我不能,因为父容器已自动销毁

您不需要构建整个Dockerfile,您可以在构建的某个阶段停止。只需使用如下命令进行构建:

docker build --target builder -t alexellis2/href-counter:latest .

示例取自官方文档,您可以在此处阅读更多内容:“在特定构建阶段停止”.

你想实现什么?@LinPy我想强制docker保留中间容器。但目的是什么?你不能运行输出映像并检查需要检查的内容吗?你可以
运行哪个python&&pip安装git+https://github.com/heig-vd-tin/sphinx-heigvd-theme.git
您不需要保留图像
docker build --target builder -t alexellis2/href-counter:latest .