Tuesday 9 October 2018

Setting the Proxy details in different tools

Many times when we are switching our work between the home network and office network, we may face this proxy issues if the office network is under proxy. 

And most of the time, just setting the system level proxy won't be enough, we need to set the proxy at each application/tools level. In this blog, I wanted to document setting up of proxies setting for few of the development tools


1. Maven

For maven, the proxy details need to be mentioned in the setting.xml file. There may be two copies of this settings.xml file one at the global level and one per user account. If we prefer to affect only the current user, then we need to edit the user's copy of setting.xml. The maven is a little intelligent and it will automatically detect and adds the proxy details in the setting.xml but the problem is I haven't seen them removing the proxy details when we are the home network, we need to manually remove it.

In Ubuntu, the setting.xml can be found from below path
/opt/etc/maven/conf/settings.xml
https://maven.apache.org/settings.html

2. Docker

The interesting thing with Docker is, we need to mention the proxy setting in two places. The first one is for the 'docker' command to work in the host environment. Another one is for passing the proxy details to the guest containers.


Proxy for the host:


  • Create the folder

$ sudo mkdir -p /etc/systemd/system/docker.service.d

  • Create the file

/etc/systemd/system/docker.service.d/http-proxy.conf

  • Add the following entry in the file

[Service]Environment="HTTP_PROXY=http://proxy.example.com:80/"

https://docs.docker.com/config/daemon/systemd/#httphttps-proxy


Proxy for the guest containers:

One option for this is to set the environment variables in the Dockerfile. But the recommended approach is to set via the config.json

https://docs.docker.com/network/proxy/


3. NPM

The node package manager does not take the system proxy settings. We need to set it via its npm config command like below


npm config set proxy http://proxy.company.com:8080
npm config set https-proxy http://proxy.company.com:8080
Inorder to unset the proxy details, execute below command
npm config rm proxy 
npm config rm https-proxy
Did you notice, even for https, it expects to provide only the HTTP proxy detail. 

https://jjasonclark.com/how-to-setup-node-behind-web-proxy/

4. Linux Terminal

It use to fetch the system proxy setting automatically; but for some reasons, sometimes it may not fetch from the system proxy settings. In such cases, we can simply export the environment variables and that should work. We should note that once we close the terminal these values will be lost

export http_proxy=http://proxy.company.com:8080 
export https_proxy=https://proxy.company.com:8080

No comments:

Post a Comment