title: How to pass a filepath into a docker file
body: <p>I'm trying to build a simple container that will allow the user to pass in a directory file path to an executable which should exist on the host machine. </p>
  
  <p>I want to have this somewhat flexible whereby if the user doesn't specify a directory filepath it will use the default one. From what I have researched I need to use <a href="https://docs.docker.com/engine/reference/builder/#arg" rel="nofollow noreferrer">ARG</a> and potentially the <a href="https://docs.docker.com/v17.09/engine/reference/run/#env-environment-variables" rel="nofollow noreferrer">-e flag</a> at run time. Lets go through an example with this simple Dockerfile. </p>
  
  <pre><code>FROM ubuntu:latest
  #Assign the default value
  ARG DIRHOME=/opt/docker/q
  #if -e has not been set the use default DIRHOME
  ADD $DIRHOME /q
  </code></pre>
  
  <p>The Dockerfile resides in a folder /opt/docker where I will run </p>
  
  <pre><code>docker build --build-arg DIRHOME=/q .
  </code></pre>
  
  <p>This all runs successfully but as you can see I am always using the default value. Is there a way for the user to pass their filepath to the q executable during run time to overwrite the DIRHOME variable? Something like below </p>
  
  <pre><code>docker run -e "QHOME=/user1/lib/q" &lt;container id&gt;
  </code></pre>
  
  <p>I think the problem with this is to do with build context, so if I run my Dockerfile inside /opt/docker then it treats that as its root and it can't find the path /user1/lib/q. Any potential workarounds? </p>