<p>I've made the following <code>Dockerfile</code>:</p>
<pre><code>FROM python:3.7

WORKDIR /app

# Install python dependencies
ADD requirements.txt /app/
RUN pip3 install --upgrade pip
RUN pip3 install -r requirements.txt

# Copy sources
ADD . /app

# Read arguments
ARG top_k=5
ARG threshold=0.5
ARG broker=broker.mqttdashboard.com
ARG port=8000
ARG topic=topic/truc

# Run detection
CMD python3 detect.py --top_k ${top_k} --threshold ${threshold} --broker ${broker} --port ${port} --topic ${topic}
</code></pre>
<p>The building works great but when I try to run the container, I got an error saying the arguments are missing:</p>
<pre><code>usage: detect.py [-h] [--top_k TOP_K] [--threshold THRESHOLD]
                 [--broker BROKER] [--port PORT] [--topic TOPIC]
detect.py: error: argument --top_k: expected one argument
</code></pre>
<p>The python code is very basic:</p>
<pre><code>parser = argparse.ArgumentParser()
parser.add_argument('--top_k', type=int, default=3, help='Number of categories with highest score to display')
args = parser.parse_args()
</code></pre>
<p>Is there something I don't understand with Docker <code>ARG</code> ?
My plan is to edit these arguments in the <code>kubernetes</code> yaml file.</p>

Manitoba
<p><code>ARG</code> doesn't make sense here.  It's a way to pass in options when you build the image, but to change those options you'd need to rebuild it.  In this case you're just trying to provide the options when you run the script.</p>
<p>One approach is to just pass these options as command-line options.  Have a default <code>CMD</code> that runs the script, but override that when you run the container.</p>
<pre class="lang-sh prettyprint-override"><code># In the Dockerfile, no ARGs, and a default
CMD ./detect.py
</code></pre>
<pre class="lang-sh prettyprint-override"><code>docker run --rm ... my/image \
  ./detect.py --top_k 5
</code></pre>
<p>A variant here is to provide the command as <code>ENTRYPOINT</code> and the options as <code>CMD</code>.</p>
<pre class="lang-sh prettyprint-override"><code>ENTRYPOINT [&quot;./detect.py&quot;] # must be JSON-array form
# CMD [&quot;--help&quot;]           # must be JSON-array form
</code></pre>
<pre class="lang-sh prettyprint-override"><code>docker run --rm ... my/image \
  --top_k 5
</code></pre>
<p>In both cases, Kubernetes <code>args:</code> specifies the &quot;command&quot; part after the image name in the <code>docker run</code> command.</p>
<pre class="lang-yaml prettyprint-override"><code>image: my/image
args:
  - --top_k
  - 5
</code></pre>
<p>It might be more manageable to update your application code to accept these options directly as environment variables</p>
<pre class="lang-py prettyprint-override"><code>parser.add_argument('--top_k', type=int,
  default=int(os.environ.get('TOP_K', '3')), # &lt;-----
  help='Number of categories with highest score to display')
</code></pre>
<p>Then in the Dockerfile you can specify these defaults as <code>ENV</code> variables if you need to change them in a Docker context</p>
<pre class="lang-sh prettyprint-override"><code>ENV TOP_K=5
CMD [&quot;./detect.py&quot;] # with no additional arguments
</code></pre>
<p>But then it's straightforward to supply individual environment-value settings when you run the container.</p>
<pre class="lang-sh prettyprint-override"><code>docker run --rm ... \
  -e TOP_K=20 \
  my/image
</code></pre>
<pre class="lang-yaml prettyprint-override"><code>image: my/image
env:
  - name: TOP_K
    value: '20'  # must be a YAML string
</code></pre>
<p>The mechanical problem you're running into is that <a href="https://docs.docker.com/engine/reference/builder/#using-arg-variables" rel="nofollow noreferrer"><code>ARG</code> values are only inserted into the environment for <code>RUN</code> commands</a> and not the <code>ENTRYPOINT</code> or <code>CMD</code>.  The syntax you show would likely work if you used <code>ENV</code> instead of <code>ARG</code>, or used both to make the option configurable at build time but then saved in the image as an environment variable, but it's going to be trickier to set up and maintain.</p>
