0

I have a docker, DockerB, which is based on DockerA. I want to make sure that whenever DockerB is built (e.g. using docker build ... DockerB), it first builds DockerA and then builds DockerB. What is the best way to achieve that?

Currently I am using shell scripts to achieve that but that doesn't sound like a good solution since other developers can still directly run docker build and accidently use an old version of DockerA.

Please note that I don't want to merge content of both Dockerfiles because there are other dockers which depend on DockerA. So it has to be a separate docker.

Cashif Ilyas
  • 1,619
  • 2
  • 14
  • 22

1 Answers1

0

You can parametrize your dockerfile B so, that everyone has to pass the version of docker image A as a build argument:

docker build -t mydockerB --build-arg VERSION=123 ...

Dockerfile B:

ARG VERSION
FROM mydockerA:${VERSION}
...
Slava Kuravsky
  • 2,702
  • 10
  • 16
  • Thanks for the answer. It will not force anything because people build "latest" tags anyway on their local machines. They will pass "latest" and it will pick up the old available image. – Cashif Ilyas Oct 25 '22 at 10:36
  • Don't build "latest" tag, it's only bad name convention – Slava Kuravsky Oct 25 '22 at 11:38