
现在有一个项目,其中用到了多个 Dockerfile,每个 Dockerfile 都会用到上一个,2.0,0 的第一行就是FROM test:1.0.0,需要多次 build 才能得到最终的。 示例:
先执行 docker build -f cpu/1.0.0/Dockerfile -t test:1.0.0 .
再执行 docker build -f cpu/2.0.0/Dockerfile -t test:2.0.0 .
...
再执行 docker build -f cpu/2.0.6/Dockerfile -t test:2.0.6 .
目录树类似如下:
|-- cpu | |-- 1.0.0 | | |-- Dockerfile | | |-- READ.md | | `-- run-noroot.sh | |-- 2.0.0 | | |-- Dockerfile | | |-- READ.md | | |-- requirement-py2.txt | | |-- requirement-py3.txt | | `-- run-root.sh | |-- 2.0.4 | | |-- Dockerfile | | |-- READ.md | | `-- run-root.sh | |-- 2.0.5 | | |-- Dockerfile | | |-- READ.md | | |-- etc | | | `-- sudoers | | |-- notebook | | | |-- __init__.py | | `-- run-jupyter.sh | `-- 2.0.6 | |-- Dockerfile | `-- READ.md 这样的项目,如何执行一次命令构建出来。
我能想到两个方法,二是重写一个 Dockerfile,然后把其他的都整理进来,太麻烦; 二是用 Makefile 来做,还在尝试
1 AoEiuV020 2021-08-12 14:20:50 +08:00 一般是二,不过官方有个 multi-stage 针对这种情况, |
2 enng 2021-08-12 14:23:33 +08:00 docker 的多阶段构建尝试了么 |
3 swulling 2021-08-12 14:24:01 +08:00 |
4 amrom OP |
5 AoEiuV020 2021-08-12 14:58:09 +08:00 |
6 Bazingal 2021-08-12 14:59:45 +08:00 为什么一定要依赖上一步生成的镜像?除非最终生成的每一个镜像都是有用的,那么写个 bash 脚本也可以解决。如果你只是要最终的镜像,完全可以用多阶段构建 |
7 qaz168000 2021-08-12 17:47:08 +08:00 用 dockercompose 来做 或者就是 dockerfile 中用--from=上一步镜像 |