0

I have the need to pass a variable at runtime when the docker run command is run and the same is to be read inside the container.

This is the docker run command that i use

docker run  -it -e "URL=test" test bash

But the variable URL is not available inside the container. My Dockerfile as below

FROM ubuntu

RUN apt-get update
RUN echo "test"
RUN echo "The url is " $URL >> /out.log

Inside the container, out.log shows only the following ouput

The url is

What am i missing?

Manikandan Kannan
  • 8,684
  • 15
  • 44
  • 65
  • 2
    `RUN` inside a Dockerfile is used at "build" time, not when you `docker run` new containers. – tgogos Jan 17 '19 at 09:57

1 Answers1

1

If you need this variable available during build time, use --build-arg - documentation here.

If you need this variable available during run (container) time, then use an environment variable and define an ENTRYPOINT script that does whatever it needs using this variable.

DannyB
  • 12,810
  • 5
  • 55
  • 65
  • 1
    I have a similar problem. I define an ENV variable at build time like ENV a 1. But when I run the image, this a is not present. What am I doing wrong? – nullpointer Apr 28 '23 at 15:54