Thursday 2 February 2017

Docker : Setting Proxy for Corporate Network

In some of the corporate networks, you will need to set the proxy settings for Docker to be able to communicate with external world. Usually the proxy is of the format 
'http://<username>:<password>@<hostname>:<port>'

For some linux versions on which Docker is installed, the setting can be made in 

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

Create a file called /etc/systemd/system/docker.service.d/http-proxy.conf that adds the HTTP_PROXY environment variable:

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


If you have internal Docker registries that you need to contact without proxying you can specify them via the NO_PROXY environment variable:
Environment="HTTP_PROXY=http://proxy.example.com:80/" "NO_PROXY=localhost,127.0.0.1,docker-registry.somecorporation.com"

$ sudo systemctl daemon-reload
$ systemctl show --property=Environment docker
Environment=HTTP_PROXY=http://proxy.example.com:80/
$ sudo systemctl restart docker

 


NOTE: For some version of Linux (say Oracle), you will need to set the proxy settings in 
$ cat /etc/sysconfig/docker
# /etc/sysconfig/docker
#
# Other arguments to pass to the docker daemon process
# These will be parsed by the sysv initscript and appended
# to the arguments list passed to docker daemon

other_args=""
export HTTP_PROXY="http://myproxy:80"
export HTTPS_PROXY="http://
myproxy:80"
HTTP_PROXY="http://
myproxy:80"
HTTPS_PROXY="http://
myproxy:80"

Restart the docker service,
# /etc/init.d/docker restart
Stopping docker:                                           [  OK  ]
Starting docker:        .                                  [  OK  ]

 

Wednesday 1 February 2017

Yum with Python 3 : except KeyboardInterrupt, e: SyntaxError: invalid syntax

If your machine has Python 3 installed (or upgraded to Python3), then running yum will fail with below error 

[sbetha@host:pwd]$ yum
  File "/usr/bin/yum", line 30
    except KeyboardInterrupt, e:
                            ^
SyntaxError: invalid syntax

 

This is because, yum doesnt support Python 3 at the moment.
Check which all versions of Python are installed on your machine
$ ls -lrt  /usr/bin/python*
-rwxr-xr-x. 1 root root 1418 Jan 22  2014 /usr/bin/python2.6-config
-rwxr-xr-x  2 root root 9032 Jan 22  2014 /usr/bin/python266
-rwxr-xr-x  2 root root 9032 Jan 22  2014 /usr/bin/python2.6
lrwxrwxrwx. 1 root root    6 Apr 22  2015 /usr/bin/python2 -> python
lrwxrwxrwx. 1 root root   16 Apr 22  2015 /usr/bin/python-config -> python2.6-config
lrwxrwxrwx  1 root root   24 Aug 26 00:18 /usr/bin/python2.7 -> /root/py27/bin/python2.7
lrwxrwxrwx  1 root root   40 Jan 31 22:59 /usr/bin/python -> /scratch/sbetha/python_3.4.6/bin/python3
 

Edit /usr/bin/yum to include on line1 as 
$ cat /usr/bin/yum
#!/usr/bin/python2.6

 
Now yum will work as normal since it uses Python 2.6
$ yum --version
3.2.29
  Installed: rpm-4.8.0-37.el6.x86_64 at 2015-04-22 15:54
  Built    : None at 2013-10-14 13:39
  Committed: Panu Matilainen <pmatilai@redhat.com> at 2013-09-12

  Installed: yum-3.2.29-60.0.1.el6.noarch at 2015-04-22 15:54
  Built    : None at 2014-08-25 14:22
  Committed: Jacob Wang <jacob.wang@oracle.com> at 2014-08-21

  Installed: yum-plugin-aliases-1.1.30-30.0.1.el6.noarch at 2015-04-22 16:11
  Built    : None at 2014-10-15 23:40
  Committed: Curt Carter <curt.carter@oracle.com> at 2014-10-14

  Installed: yum-plugin-fastestmirror-1.1.30-30.0.1.el6.noarch at 2015-04-22 18:24
  Built    : None at 2014-10-15 23:40
  Committed: Curt Carter <curt.carter@oracle.com> at 2014-10-14

 

Linux : Create a new user for the machine

Creating a new user in linux is sometimes needed, when you want to share the user access with anyone. SSH to the machine over the newly cre...