oskarryn
oskarryn

Reputation: 383

Override parent Docker arguments

Let the parent Docker some_img have argument X set to '0'.

How to override the argument value and have the parent Docker use other X?

I tried

ARG X='1'
FROM some_img:latest

...do stuff...

but clearly some_img still uses X='0' because ARG='0' is specified in some_img Dockerfile. ENV would take precedence over ARG, but this is not allowed before FROM.

Note that if I were just to build some_img, I could override ARG in Dockerfile by using --build-arg option in docker build.

Is there any way to override arguments in parent Docker?

Upvotes: 4

Views: 1546

Answers (1)

David Maze
David Maze

Reputation: 159505

No, there's no way to do this.

The result of docker build is an opaque, immutable image. A downstream Dockerfile's FROM line doesn't rebuild the image, it simply imports that opaque image as-is. You can't change what's in the image or its build options after it's been built, or cause it to be rebuilt in the later Dockerfile.

If you control both images, it's possible the thing you're trying to change shouldn't be a build-time ARG at all. Things like upstream package version numbers can be good ARGs (a Java 8 vs. Java 11 version of something is likely "different" enough to merit two builds but still be quite similar on the whole; updating from version 3.4.1 to 3.4.2 of some library probably only involves changing a version number but not any logic). Things where you need to control the behavior later on (numeric user IDs, database locations, ...) should be configured some other way and not built in to an image.

Upvotes: 7

Related Questions