<p>Consider a the following <code>docker</code> command, which builds an image from a Dockerfile:</p>
<p><code>docker image build --network host -t test -f Dockerfile .</code></p>
<p>Is it possible to specify options of <code>docker image build</code> in the Dockerfile instead of the command-line (in this case <code>--network host</code>)?</p>
<p>This could be useful, since the host running <code>docker image build ...</code> uses a set of fixed flags, which would overriden by custom flags.</p>

Shuzheng
<p>In general, no.</p>
<p>In this particular case (network access): kinda, actually, using BuildKit, a new build system for Docker.</p>
<p>If you're using BuildKit (<code>export DOCKER_BUILDKIT=1</code>) you can add a comment at the top of the Dockerfile to enable newer syntax. And you can specify different versions of the syntax, which basically works by downloading a new builder, implemented a Docker image.</p>
<p>(A lot more details here: <a href="https://pythonspeed.com/articles/docker-buildkit/" rel="nofollow noreferrer">https://pythonspeed.com/articles/docker-buildkit/</a>).</p>
<p>The latest experimental BuildKit syntax has an option for setting network access per build step. Scroll to bottom of <a href="https://hub.docker.com/r/docker/dockerfile/" rel="nofollow noreferrer">https://hub.docker.com/r/docker/dockerfile/</a> for details, but short version:</p>
<ol>
<li>Add <code>#syntax=docker/dockerfile:1.2-labs</code> as first line of Dockerfile.</li>
<li>Change <code>RUN mycommand</code> to <code>RUN --network=host mycommand</code>.</li>
</ol>
