我正在从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
但是我不能,因为父容器被自动破坏了。
答案 0 :(得分:2)
您不需要构建整个Dockerfile,可以在构建的某个阶段停止。只需使用以下命令进行构建:
docker build --target builder -t alexellis2/href-counter:latest .
摘自官方文档的示例,您可以在此处阅读更多信息:https://docs.docker.com/develop/develop-images/multistage-build/在“在特定构建阶段停止”下。