<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Docker Proxy Settings &#8211; Best DevOps</title>
	<atom:link href="https://www.bestdevops.com/tag/docker-proxy-settings/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.bestdevops.com</link>
	<description>Lets Learn, Do it &#38; Share! Thats a Best DevOps!!!</description>
	<lastBuildDate>Mon, 12 Oct 2026 08:16:22 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=7.1.3</generator>
	<item>
		<title>Using Docker Behind a Corporate Proxy</title>
		<link>https://www.bestdevops.com/using-docker-behind-a-proxy/</link>
					<comments>https://www.bestdevops.com/using-docker-behind-a-proxy/#respond</comments>
		
		<dc:creator><![CDATA[anil]]></dc:creator>
		<pubDate>Mon, 03 Apr 2017 07:59:20 +0000</pubDate>
				<category><![CDATA[DevOps]]></category>
		<category><![CDATA[DevOps Process]]></category>
		<category><![CDATA[DevOps Tools]]></category>
		<category><![CDATA[Docker]]></category>
		<category><![CDATA[Docker COntainer]]></category>
		<category><![CDATA[Docker Proxy Configuration]]></category>
		<category><![CDATA[Docker Proxy Settings]]></category>
		<category><![CDATA[Proxy Configuration]]></category>
		<guid isPermaLink="false">http://www.bestdevops.com/?p=1124</guid>

					<description><![CDATA[Running Docker inside a corporate network with a web proxy? Learn how to configure the Docker daemon, Dockerfile ENV variables, and build arguments so that both image pulls and in-container package managers work correctly behind a proxy.]]></description>
										<content:encoded><![CDATA[
<p class="wp-block-paragraph">Running Docker inside a large corporate network often means that direct internet access is blocked and all outbound traffic must pass through an HTTP proxy. Docker&#8217;s default behavior assumes unrestricted internet access, so you will hit connectivity errors when trying to pull images or install packages inside a container. This article walks through every layer of proxy configuration you need to address: the Docker daemon, the container build environment, and the container runtime.</p>



<h2 class="wp-block-heading">The Problem: Two Separate Network Contexts</h2>



<p class="wp-block-paragraph">A proxy misconfiguration with Docker almost always comes down to one misunderstood fact: <strong>there are two separate network contexts that each need independent proxy settings</strong>.</p>



<ul class="wp-block-list">
<li><strong>The Docker daemon</strong> — responsible for pulling base images from registries such as Docker Hub.</li>
<li><strong>The container build/run environment</strong> — the isolated environment in which your <code>RUN</code> instructions execute. Tools like <code>apt-get</code>, <code>yum</code>, <code>curl</code>, and <code>pip</code> run here and have no knowledge of the host&#8217;s proxy settings.</li>
</ul>



<p class="wp-block-paragraph">Configuring one without the other will leave you with partial failures. The sections below address each context in turn.</p>



<h2 class="wp-block-heading">A Simple Example Dockerfile</h2>



<p class="wp-block-paragraph">Throughout this article we will use a minimal Ubuntu-based image that installs <code>curl</code> via <code>apt-get</code>. This is intentionally simple, but it exercises both proxy contexts.</p>


<pre class="wp-block-code"><span><code class="hljs language-javascript">FROM ubuntu

RUN apt-<span class="hljs-keyword">get</span> update &amp;&amp; apt-<span class="hljs-keyword">get</span> install -y curl</code></span></pre>


<p class="wp-block-paragraph">Attempting to build this image on a network with no direct internet access produces an error immediately at the <code>FROM</code> step:</p>


<pre class="wp-block-code"><span><code class="hljs language-javascript">$ sudo docker build -t curl .
Sending build context to Docker daemon <span class="hljs-number">12.29</span> kB
Step <span class="hljs-number">0</span> : FROM ubuntu
Pulling repository ubuntu
INFO&#91;<span class="hljs-number">0002</span>] Get https:<span class="hljs-comment">//index.docker.io/v1/repositories/library/ubuntu/images: dial tcp 52.22.146.88:443: connection refused</span></code></span></pre>


<p class="wp-block-paragraph">The daemon cannot reach Docker Hub because outbound TCP connections are blocked. Fix this first.</p>



<h2 class="wp-block-heading">Step 1 — Configuring the Docker Daemon to Use a Proxy (Ubuntu host)</h2>



<p class="wp-block-paragraph">On Ubuntu hosts that use the older SysV init system, Docker&#8217;s environment is sourced from <code>/etc/default/docker</code>. That file includes a commented-out proxy line:</p>


<pre class="wp-block-code"><span><code class="hljs language-php"><span class="hljs-comment"># If you need Docker to use an HTTP proxy, it can also be specified here.</span>
<span class="hljs-comment">#export http_proxy="http://127.0.0.1:3128/"</span></code></span></pre>


<p class="wp-block-paragraph">Uncomment the line and replace the placeholder with your actual proxy address:</p>


<pre class="wp-block-code"><span><code class="hljs language-php"><span class="hljs-comment"># If you need Docker to use an HTTP proxy, it can also be specified here.</span>
export http_proxy=<span class="hljs-string">"http://192.168.33.10:3128/"</span></code></span></pre>


<p class="wp-block-paragraph">If your proxy requires authentication, embed the credentials in the URL:</p>


<pre class="wp-block-code"><span><code class="hljs language-javascript"><span class="hljs-keyword">export</span> http_proxy=<span class="hljs-string">"http://username:password@192.168.33.10:3128/"</span></code></span></pre>


<h3 class="wp-block-heading">systemd-based hosts</h3>



<p class="wp-block-paragraph">Most modern Ubuntu and Debian installations (16.04 and later) manage Docker with <strong>systemd</strong>, which does not read <code>/etc/default/docker</code> for environment variables. For systemd, create a drop-in override file instead:</p>


<pre class="wp-block-code"><span><code class="hljs language-javascript">sudo mkdir -p /etc/systemd/system/docker.service.d
sudo tee /etc/systemd/system/docker.service.d/http-proxy.conf &lt;&lt;EOF
&#91;Service]
Environment=<span class="hljs-string">"HTTP_PROXY=http://192.168.33.10:3128/"</span>
Environment=<span class="hljs-string">"HTTPS_PROXY=http://192.168.33.10:3128/"</span>
Environment=<span class="hljs-string">"NO_PROXY=localhost,127.0.0.1"</span>
EOF
sudo systemctl daemon-reload
sudo systemctl restart docker</code></span></pre>


<p class="wp-block-paragraph">For the SysV approach, restart Docker with the <code>service</code> command:</p>


<pre class="wp-block-code"><span><code class="hljs language-php"><span class="hljs-comment"># service docker restart</span>
docker stop/waiting
docker start/running, process <span class="hljs-number">32703</span></code></span></pre>


<p class="wp-block-paragraph">After restarting, <code>docker pull</code> and the <code>FROM</code> step of a build will route through your proxy. However, <code>RUN</code> instructions that use <code>apt-get</code> or other network tools will still fail because the container environment has no proxy configured.</p>



<h2 class="wp-block-heading">Step 2 — Configuring the Proxy Inside the Container</h2>



<p class="wp-block-paragraph">After configuring the daemon proxy, re-running the build pulls the Ubuntu base image successfully — but <code>apt-get update</code> immediately fails:</p>


<pre class="wp-block-code"><span><code class="hljs language-javascript">Step <span class="hljs-number">1</span> : RUN apt-<span class="hljs-keyword">get</span> update &amp;&amp; apt-<span class="hljs-keyword">get</span> install -y curl
 ---&gt; Running in 39b964be90bc
Err:1 http://archive.ubuntu.com/ubuntu xenial InRelease
  Cannot initiate the connection to archive.ubuntu.com:80. - connect (101: Network is unreachable)
E: Unable to locate package curl</code></span></pre>


<p class="wp-block-paragraph">This happens because the container&#8217;s network environment is isolated from the host. The <code>http_proxy</code> variable set on the host is not inherited inside the container&#8217;s build shell.</p>



<h3 class="wp-block-heading">Option A — Pass proxy settings as build arguments</h3>



<p class="wp-block-paragraph">Use <code>--build-arg</code> to inject the proxy at build time without hardcoding it in the Dockerfile:</p>


<pre class="wp-block-code"><span><code class="hljs language-javascript">$ sudo docker build -t curl \
  --build-arg http_proxy=http:<span class="hljs-comment">//192.168.33.10:3128 \</span>
  --build-arg https_proxy=http:<span class="hljs-comment">//192.168.33.10:3128 \</span>
  .</code></span></pre>


<p class="wp-block-paragraph">This approach is preferred when you want to keep the Dockerfile portable — colleagues on networks without a proxy can build the same file without modification.</p>



<h3 class="wp-block-heading">Option B — Set proxy variables in the Dockerfile with ENV</h3>



<p class="wp-block-paragraph">Alternatively, declare the proxy variables directly in the Dockerfile using <code>ENV</code> instructions:</p>


<pre class="wp-block-code"><span><code class="hljs language-javascript">FROM ubuntu

ENV http_proxy <span class="hljs-string">"http://192.168.33.10:3128"</span>
ENV https_proxy <span class="hljs-string">"http://192.168.33.10:3128"</span>
RUN apt-<span class="hljs-keyword">get</span> update &amp;&amp; apt-<span class="hljs-keyword">get</span> install -y curl</code></span></pre>


<p class="wp-block-paragraph">Both <code>apt-get</code> and <code>curl</code> respect the standard <code>http_proxy</code> / <code>https_proxy</code> environment variables, so this is sufficient for most Linux package managers and command-line HTTP tools.</p>



<h2 class="wp-block-heading">Step 3 — Verifying the Build and Runtime Behaviour</h2>



<p class="wp-block-paragraph">With proxy variables set, the build completes successfully:</p>


<pre class="wp-block-code"><span><code class="hljs language-javascript">$ sudo docker build -t curl .
...
Step <span class="hljs-number">1</span> : ENV http_proxy <span class="hljs-string">"http://192.168.33.10:3128"</span>
Step <span class="hljs-number">2</span> : ENV https_proxy <span class="hljs-string">"http://192.168.33.10:3128"</span>
Step <span class="hljs-number">3</span> : RUN apt-<span class="hljs-keyword">get</span> update &amp;&amp; apt-<span class="hljs-keyword">get</span> install -y curl
Get:1 http://archive.ubuntu.com/ubuntu xenial InRelease &#91;247 kB]
Get:2 http://archive.ubuntu.com/ubuntu xenial-updates InRelease &#91;102 kB]
...</code></span></pre>


<p class="wp-block-paragraph">Running the container and making an outbound request with <code>curl</code> shows that traffic is also routed through the proxy at runtime:</p>


<pre class="wp-block-code"><span><code class="hljs language-javascript">$ sudo docker run curl curl -v http:<span class="hljs-comment">//example.com</span>
*   Trying <span class="hljs-number">192.168</span><span class="hljs-number">.33</span><span class="hljs-number">.10</span>...
&gt; GET http:<span class="hljs-comment">//example.com/ HTTP/1.1</span>
&gt; <span class="hljs-built_in">Proxy</span>-Connection: Keep-Alive
&lt; HTTP/<span class="hljs-number">1.1</span> <span class="hljs-number">200</span> OK</code></span></pre>


<p class="wp-block-paragraph">Notice the <code>Proxy-Connection</code> header — the request was forwarded via the proxy.</p>



<h2 class="wp-block-heading">Unsetting Proxy Variables After the Build Step</h2>



<p class="wp-block-paragraph">Because <code>ENV</code> instructions persist into the running container, any process that respects <code>http_proxy</code> will automatically use the proxy at runtime — which may not be what you want if the proxy is only reachable from the build network. To scope proxy settings to the build phase only, unset them after your package installation step:</p>


<pre class="wp-block-code"><span><code class="hljs language-javascript">FROM ubuntu

ENV http_proxy <span class="hljs-string">"http://192.168.33.10:3128"</span>
ENV https_proxy <span class="hljs-string">"http://192.168.33.10:3128"</span>
RUN apt-<span class="hljs-keyword">get</span> update &amp;&amp; apt-<span class="hljs-keyword">get</span> install -y curl
ENV http_proxy ""
ENV https_proxy ""</code></span></pre>


<p class="wp-block-paragraph">When the container is launched with <code>docker run</code>, the proxy variables will be empty and outbound connections from application code will go directly to the network (or fail gracefully if the runtime network also requires a proxy).</p>



<p class="wp-block-paragraph">Alternatively, you can override environment variables at runtime without modifying the Dockerfile:</p>


<pre class="wp-block-code"><span><code class="hljs language-javascript">$ sudo docker run -e http_proxy=<span class="hljs-string">""</span> -e https_proxy=<span class="hljs-string">""</span> curl curl http:<span class="hljs-comment">//example.com</span></code></span></pre>


<h2 class="wp-block-heading">Docker Desktop (Mac and Windows)</h2>



<p class="wp-block-paragraph">Docker Desktop on macOS and Windows exposes proxy settings through the application&#8217;s graphical preferences panel. Navigate to <strong>Settings → Resources → Proxies</strong> and enable <em>Manual proxy configuration</em> to specify HTTP and HTTPS proxy addresses.</p>



<p class="wp-block-paragraph">This configures the Docker Desktop daemon&#8217;s outbound proxy for image pulls. It does <strong>not</strong> automatically inject proxy variables into container build or run environments — you still need to use <code>ENV</code> instructions or <code>--build-arg</code> for that.</p>



<h2 class="wp-block-heading">Quick Reference: Which Setting Does What</h2>



<figure class="wp-block-table"><table><thead><tr><th>Configuration</th><th>What it affects</th><th>Required for image pulls</th><th>Required for in-container network access</th></tr></thead><tbody><tr><td><code>/etc/default/docker</code> or systemd drop-in</td><td>Docker daemon process</td><td>Yes</td><td>No</td></tr><tr><td><code>--build-arg http_proxy=…</code></td><td>Build-time environment only</td><td>No</td><td>Yes (build only)</td></tr><tr><td><code>ENV http_proxy</code> in Dockerfile</td><td>Build-time and runtime environment</td><td>No</td><td>Yes (build and run)</td></tr><tr><td><code>docker run -e http_proxy=…</code></td><td>Runtime environment only</td><td>No</td><td>Yes (run only)</td></tr><tr><td>Docker Desktop Proxies UI</td><td>Docker daemon process on Mac/Windows</td><td>Yes</td><td>No</td></tr></tbody></table></figure>



<h2 class="wp-block-heading">Summary</h2>



<p class="wp-block-paragraph">Getting Docker to work behind a corporate proxy requires addressing two independent layers:</p>



<ol class="wp-block-list">
<li><strong>The Docker daemon</strong> — configure <code>HTTP_PROXY</code> / <code>HTTPS_PROXY</code> via the systemd drop-in file (modern systems) or <code>/etc/default/docker</code> (older SysV systems), then restart the service.</li>
<li><strong>The container environment</strong> — pass proxy settings via <code>--build-arg</code> or <code>ENV</code> instructions in the Dockerfile so that package managers and other tools inside the container can reach external repositories.</li>
</ol>



<p class="wp-block-paragraph">Remember that <code>ENV</code>-declared proxy variables persist into the running container. Unset them after your installation steps, or override them with <code>docker run -e</code>, if you do not want runtime traffic to traverse the proxy.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.bestdevops.com/using-docker-behind-a-proxy/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
