1

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

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

Removing intermediate container dac6772bcf71
 ---> aa6de00f27db

所以我不能这样做:

docker run -it dac6772bcf71 /bin/bash

我找到了--force-rm选项,但没有找到keep-intermediate

如何告诉 Docker 保留中间容器?

具体例子

IRL,我有这个:

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}'

所以看来我的 Python < 3.6,但我想检查一下。一种可能性是:

docker run dac6772bcf71 python --version

但我不能,因为父容器被自动销毁了。

4

1 回答 1

2

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

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

示例取自官方文档,您可以在此处阅读更多内容:https ://docs.docker.com/develop/develop-images/multistage-build/在“在特定构建阶段停止”下。

于 2019-08-14T13:36:29.180 回答