<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: Tushar Rao</title>
    <description>The latest articles on Forem by Tushar Rao (@tusharrao198).</description>
    <link>https://forem.com/tusharrao198</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F506500%2F0706e422-c523-47e5-8192-62499cc1e991.jpg</url>
      <title>Forem: Tushar Rao</title>
      <link>https://forem.com/tusharrao198</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/tusharrao198"/>
    <language>en</language>
    <item>
      <title>Setting Network Proxy in Docker in linux</title>
      <dc:creator>Tushar Rao</dc:creator>
      <pubDate>Sun, 19 Feb 2023 10:07:37 +0000</pubDate>
      <link>https://forem.com/tusharrao198/setting-network-proxy-in-docker-in-linux-h7j</link>
      <guid>https://forem.com/tusharrao198/setting-network-proxy-in-docker-in-linux-h7j</guid>
      <description>&lt;p&gt;Note: Combined all resources into one.&lt;br&gt;
To run Docker in Ubuntu with a proxy, follow these steps:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;Set the proxy in the Docker daemon by editing the Docker service file:&lt;br&gt;
&lt;/p&gt;

&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sudo &lt;/span&gt;systemctl edit docker.service
&lt;/code&gt;&lt;/pre&gt;



&lt;p&gt;Then paste the following:&lt;br&gt;
&lt;/p&gt;

&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# A Systemd service definition to set proxy configuration for Docker engine on Linux

[Service]
Environment="HTTP_PROXY=http://proxy:proxy_port"
Environment="HTTPS_PROXY=http://proxy:proxy_port"
Environment="NO_PROXY=localhost,127.0.0.1"
&lt;/code&gt;&lt;/pre&gt;



&lt;p&gt;If authentication is required, provide your laptop credentials:&lt;br&gt;
&lt;/p&gt;

&lt;pre class="highlight plaintext"&gt;&lt;code&gt;[Service]
Environment="HTTP_PROXY=http://username:password@proxy:proxy_port"
Environment="HTTPS_PROXY=http://username:password@proxy:proxy_port"
Environment="NO_PROXY=localhost,127.0.0.1"
&lt;/code&gt;&lt;/pre&gt;




&lt;/li&gt;
&lt;li&gt;

&lt;p&gt;Set the proxy for Docker client to run and pull images:&lt;br&gt;
&lt;/p&gt;

&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sudo mkdir&lt;/span&gt; ~/.docker/
&lt;span class="nb"&gt;sudo &lt;/span&gt;nano ~/.docker/config.json
&lt;/code&gt;&lt;/pre&gt;



&lt;p&gt;Then paste the following:&lt;br&gt;
&lt;/p&gt;

&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{
 "proxies":
 {
   "default":
   {
     "httpProxy": "http://proxy:proxy_port",
     "httpsProxy": "http://proxy:proxy_port",
     "ftpProxy": "http://proxy:proxy_port",
     "noProxy": "*.test.example.com,.example2.com,127.0.0.0/8"
   }
 }
}
&lt;/code&gt;&lt;/pre&gt;



&lt;p&gt;If authentication is required, provide your laptop credentials:&lt;br&gt;
&lt;/p&gt;

&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{
 "proxies":
 {
   "default":
   {
     "httpProxy": "http://username:password@proxy:proxy_port",
     "httpsProxy": "http://username:password@proxy:proxy_port",
     "ftpProxy": "http://username:password@proxy:proxy_port",
     "noProxy": "*.test.example.com,.example2.com,127.0.0.0/8"
   }
 }
}
&lt;/code&gt;&lt;/pre&gt;




&lt;/li&gt;
&lt;li&gt;

&lt;p&gt;Set the proxy for Docker Compose:&lt;/p&gt;

&lt;p&gt;Create a folder for configuring Docker service through systemd:&lt;br&gt;
&lt;/p&gt;

&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;mkdir&lt;/span&gt; /etc/systemd/system/docker.service.d
&lt;/code&gt;&lt;/pre&gt;



&lt;p&gt;Create a service configuration file at &lt;code&gt;/etc/systemd/system/docker.service.d/http-proxy.conf&lt;/code&gt;, and paste the following:&lt;br&gt;
&lt;/p&gt;

&lt;pre class="highlight plaintext"&gt;&lt;code&gt;[Service]
 # NO_PROXY is optional and can be removed if not needed
 # Change proxy_url to your proxy IP or FQDN and proxy_port to your proxy port
 # For Proxy server which require username and password authentication, just add the proper username and password to the URL. (see example below)

 # Example without authentication
 Environment="HTTP_PROXY=http://proxy_url:proxy_port" "NO_PROXY=localhost,127.0.0.0/8"

 # Example with authentication
 Environment="HTTP_PROXY=http://username:password@proxy_url:proxy_port" "NO_PROXY=localhost,127.0.0.0/8"
&lt;/code&gt;&lt;/pre&gt;




&lt;/li&gt;
&lt;li&gt;

&lt;p&gt;Reload &lt;code&gt;systemctl&lt;/code&gt; so that the new settings are read:&lt;br&gt;
&lt;/p&gt;

&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sudo &lt;/span&gt;systemctl daemon-reload
&lt;/code&gt;&lt;/pre&gt;



&lt;p&gt;Verify that the Docker service environment is properly set:&lt;br&gt;
&lt;/p&gt;

&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sudo &lt;/span&gt;systemctl show docker &lt;span class="nt"&gt;--property&lt;/span&gt; Environment
&lt;/code&gt;&lt;/pre&gt;




&lt;/li&gt;
&lt;li&gt;

&lt;p&gt;Restart the Docker service so that it uses the updated environment settings:&lt;br&gt;
&lt;/p&gt;

&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sudo &lt;/span&gt;systemctl restart docker
&lt;/code&gt;&lt;/pre&gt;




&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Another: To Set proxy in Dockerfile
&lt;/h2&gt;

&lt;p&gt;To make the Docker images accessible to the proxy, you need to set the proxy in the Dockerfile that contains all the commands to be executed for the Docker images. You can do this by adding the following environment variables to the Dockerfile:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;ENV http_proxy http://proxy:proxy_port
ENV https_proxy http://proxy:proxy_port
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If the above doesn't work then you need to set authentication also, try below&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;ENV http_proxy http://username:password@proxy_url:proxy_port
ENV https_proxy http://username:password@proxy_url:proxy_port
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Below is an example of how you can set up a proxy in a Dockerfile:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight docker"&gt;&lt;code&gt;&lt;span class="c"&gt;# First Stage&lt;/span&gt;
&lt;span class="k"&gt;FROM&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s"&gt;python:3.8.7-slim-buster&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="k"&gt;AS&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s"&gt;compile-image&lt;/span&gt;

&lt;span class="k"&gt;ENV&lt;/span&gt;&lt;span class="s"&gt; http_proxy http://proxy:proxy_port&lt;/span&gt;
&lt;span class="k"&gt;ENV&lt;/span&gt;&lt;span class="s"&gt; https_proxy http://proxy:proxy_port&lt;/span&gt;

&lt;span class="k"&gt;RUN &lt;/span&gt;apt-get update &lt;span class="se"&gt;\
&lt;/span&gt;    &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; apt-get &lt;span class="nb"&gt;install&lt;/span&gt; &lt;span class="nt"&gt;-y&lt;/span&gt; &lt;span class="nt"&gt;--no-install-recommends&lt;/span&gt; build-essential gcc

&lt;span class="c"&gt;# Virtual environment&lt;/span&gt;
&lt;span class="k"&gt;RUN &lt;/span&gt;python &lt;span class="nt"&gt;-m&lt;/span&gt; venv /opt/venv
&lt;span class="k"&gt;ENV&lt;/span&gt;&lt;span class="s"&gt; PATH="/opt/venv/bin:$PATH"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>docker</category>
      <category>dockerproxy</category>
      <category>webdev</category>
      <category>cloud</category>
    </item>
    <item>
      <title>Setup Network Proxy in Ubuntu Terminal</title>
      <dc:creator>Tushar Rao</dc:creator>
      <pubDate>Wed, 05 Oct 2022 11:28:55 +0000</pubDate>
      <link>https://forem.com/tusharrao198/setup-network-proxy-in-ubuntu-terminal-4417</link>
      <guid>https://forem.com/tusharrao198/setup-network-proxy-in-ubuntu-terminal-4417</guid>
      <description>&lt;p&gt;Not able to update/install any package using apt-get in Debian/Ubuntu. Accessing network in terminal when internet is configured with a proxy is troublesome sometimes.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F42uycq86blnvhztzhccv.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F42uycq86blnvhztzhccv.jpeg" alt="Image-showing-error-in-the terminal"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;As you can see in the above image, it just keeps on connecting until the server is timed out.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Below is the easiest way to setup a proxy for your network to access internet in terminal with no hassle.&lt;/p&gt;

&lt;p&gt;User need to set the proxy for apt-get. To set the proxy for apt-get, edit the file &lt;code&gt;/etc/apt/apt.conf&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;We use this acquire command to setup proxy for both http and https int the below format.&lt;/strong&gt;&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

Acquire::http::Proxy "http://proxy:port";
Acquire::https::Proxy "https://proxy:port";
Acquire::ftp::Proxy "ftp://proxy:port";


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;blockquote&gt;
&lt;p&gt;Note: Sometimes your OS requries authentication before setting up proxy for the network. For that use the below format,&lt;/p&gt;
&lt;/blockquote&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

Acquire::http::Proxy "http://[username]:[password]@ [proxy-web-or-IP-address]:[port-number]";
Acquire::https::Proxy "http://[username]:[password]@ [proxy-web-or-IP-address]:[port-number]";


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;blockquote&gt;
&lt;p&gt;The &lt;code&gt;username&lt;/code&gt; and &lt;code&gt;password&lt;/code&gt; are your laptops/PC's login username and password.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;Steps to follow:&lt;/strong&gt;
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;To define proxy settings for apt, create or edit (if it already exists) a file named apt.conf in /etc/apt directory:
```
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;sudo nano /etc/apt/apt.conf&lt;/p&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
- Add the following lines to the file:
For eg,
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Acquire::http::Proxy "&lt;a href="http://127.0.0.1:8080" rel="noopener noreferrer"&gt;http://127.0.0.1:8080&lt;/a&gt;";&lt;br&gt;
Acquire::https::Proxy "&lt;a href="http://127.0.0.1:8080" rel="noopener noreferrer"&gt;http://127.0.0.1:8080&lt;/a&gt;";&lt;/p&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
&amp;gt; Note: Here, replace these proxy and port values from your network proxy.


- Save the file by pressing Ctrl + X and then hit Enter!

- Now Source the file to update the changes in terminal.

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;source /etc/apt/apt.conf&lt;/p&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
- That's it! Now try to run the below command.

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;sudo apt-get update&lt;/p&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
![Internet-working-in-Terminal](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/eglvxrdwfrc6tqjx5psv.jpeg)

Hope it helps you guys!. Thanks for supporting.
I have posted a video explanation on Youtube. Do check it out!
&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/UdDUNp9c57k"&gt;
&lt;/iframe&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

</description>
      <category>linux</category>
      <category>ubuntu</category>
      <category>terminal</category>
      <category>tutorial</category>
    </item>
  </channel>
</rss>
