How do I add ability for child image to overwrite arg from base docker image?

Viewed 60

So I want to have an arg, but also a way to overwrite this arg via onbuild. Something like this in the base dockerfile:

ARG randvar
ONBUILD ARG randvar
ENV randvar=$randvar

In my child dockerfile I have

FROM baseimage
ARG randvar
RUN echo $randvar

But I can't seem to overwrite the ARG for some reason. This is my docker-compose file.

version: "3.9"
services:
  basec:
    build:
      context: ./dir
      dockerfile: base.Dockerfile 
      args:
        randvar: "this is orig arg"

  childc:
    build:
      context: ./dir
      dockerfile: child.Dockerfile
      args:
        randvar: "this is new arg"

First I run docker-compose run basec then docker-compose run childc My echo statement is showing "this is orig arg" instead of "this is new arg". Thx

0 Answers
Related