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

Published

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"

Source: Docker Questions

Published
Categorised as docker, docker-compose Tagged ,

Answers

Leave a Reply

Still Have Questions?


Our dedicated development team is here for you!

We can help you find answers to your question for as low as 5$.

Contact Us
faq