CyberKeeda In Social Media

How to install and configure Docker-CE on CentOS



Installation.

  • Begin with updating your system packages and docker dependencies.
$  sudo yum update
$  sudo yum install yum-utils device-mapper-persistent-data lvm2
  • Add docker stable repository for centos within your system
$  sudo yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
  • Once docker repository is enabled, proceed ahead to install Docker-CE ( Community Edition.
$  sudo yum install docker-ce
  • Now docker-ce has been installed, lets start the docker daemon and enable it on boot.
$  sudo systemctl start docker
$  sudo systemctl enable docker
  • To verify the status of  docker, run the below command.
$  sudo systemctl status docker











    • In case, if you want to check your installed docker version.
    $  sudo docker -v

    Run Docker commands without sudo

    By default managing Docker requires administrator privileges. If you want to run Docker commands as a non-root user without adding sudo within yoir command you need to add your user to the docker group which is created during the installation of the Docker CE package. Add your user to docker group by below command.

    $  sudo usermod -aG docker $USER

    Logout- Login to reflect the changes.

    Read more ...

    Python : Print() examples with parameters

    Print

    Nothing more is required to explain what does the print function does, it's name is itself self explanatory.
    Print function is used to display /print messages into the screen.

    Within python we can use ether pair of single inverted commas '  ' or double inverted "  "  within single brackets (  )  both gives the same result.

    >>> print  ('Hello World')

    Hello World

    Print() with Parameters.

    I'm adding some of the print function usage along with various parameters.

    Print() with Sep

    SEP commonly a short form of separator,  Separator between the arguments to print() function in Python is space by default (softspace feature) , which can be modified and can be made to any character, integer or string as per our choice.

    Default behaviour of python with softspace.

    >>> print('A','B','C')
    A B C

    #Trick to disable softspace using sep parameter
    >>> print('A','B','C',sep='')
    ABC

    One more example.

    >>> print('13','11','2018')
    13 11 2018

    #Trick to format a date
    >>> print('13','11','2018', sep='-')
    13-11-2018

    Print() with End

    End parameter along with print can be used to align data into a same single line along with required character,symbol or word.
    Example:

    >>> print('Welcome')
    >>> print('to')
    >>> print('cyberkeeda.com')

    Output:
    Welcome
     to
    Cyberkeeda.com
    Now, with help of end parameter, we can allign all these three different lines by one, along with extra characters too

    >>> print('Welcome', end '  ')
    >>> print('to', end '  ')
    >>> print('cyberkeeda.com', end ' ! ')
    Output:
    Welcome to Cyberkeeda.com !

    One more example ( SEP with END )
    >>> print(10,20,30,sep=':', end='...')
    >>> print(60,70,80,sep='-')

    Output:
    10:20:30...60-70-80

    Print Formatted strings and Variables on the same line.

    Before knowing anything, please note the below abbreviations.

    %i==>  int
    %d==> int
    %f==>  float
    %s==>  str

    print("formatted String" %(variable list))

    Examples.

    >>> print("value is :%d" %(12))
    value is  : 12

    >>> print("My name is :%s and age is :%d" %('Cyberkeeda',23))
    My name is : Cberkeeda and age is  : 23


    Read more ...

    Python : How to Import Modules


    Let's get to know,  what are the various ways to import a module within a python file.

    We will take example of one of the famous module named as " MATH  " and a function sqrt (used to calculate the square rootwithin the module.
    It provide access to mathematical functions defined by C,  to get to know more about it visit the official link

    Here are the various ways we can import it.

    Import the whole module.

    import math

    Usage.
    module_name.function_name

    import math
    x=16
    print(math.sqrt(16))

    Create alias of the imported module.

    In case, if you feel using such a big name of your module or nor relevant to it's behavior, you can create the module's name alias.
    Let's take the example of the same math module, i will be creating alias m for it.

    import math as m

    Usage:

    import math as m
    x=16
    print(m.sqrt(x))

    Import only specific function, functions from a particular module.

    A particular module consists of lot of functions in it, sometimes, we just need only a particular function out of entire module.
    Again let's take the same module as an example.module math contains, a lot of functions within it some  are as below.
    sqrt()
    ceil()
    floor()
    pow(x,y)
    factorial()
    fabs()
    fmod(x,y)
    sin()
    cos()

    Now, in case we need only one function sqrt() , here is the way how we only import a function from a module.

    from math import sqrt
    Usage:

    from math import sqrt
    x=16
    print(sqrt(x))

    In case, if we need more then one function.
    from math import sqrt, cos, sin
    x=16
    print(cos(x))

    Now, if you just simply don't want to write math every time and want to use all of the functions within the module.
    from math import *
    x=16
    print(cos(x))
    print(sqrt(x))
    print(sin(x))
    Read more ...

    AWK equivalent in Windows CMD




    Missing AWK on Windows ?  for /f  may help you.
    Lets see how can we implement the same.


    Example.

    C:\Users\Cyberkeeda>netsh interface show interface

    Admin State    State          Type             Interface Name
    -------------------------------------------------------------------------
    Enabled        Connected      Dedicated        Wi-Fi
    Enabled        Connected      Dedicated        VMware Network Adapter VMnet1
    Enabled        Connected      Dedicated        VMware Network Adapter VMnet8
    Enabled        Disconnected   Dedicated        Ethernet

    Lets assume we have saved the same within a file in linux names as file.txt

    Within Linux, to gather the State of interfaces, we use the below command.

    cat file.txt| awk '{print $2}'

    State
    Connected
    Connected
    Connected
    Disconnected

    In Windows, it can be accomplished with FOR /F

    C:\Users\cyberkeeda>for /f "tokens=2" %a in ('netsh interface show interface') do @echo %a

    State
    Connected
    Connected
    Connected
    Disconnected

    Now, if wish to add two values .

    cat file.txt| awk '{print $1 " " $2}'

    Admin State
    -------------------------------------------------------------------------
    Enabled Connected
    Enabled Connected
    Enabled Connected
    Enabled Disconnected

    Same can be accomplished within Windows as

    C:\Users\cyberkeeda>for /f "tokens=1,2" %a in ('netsh interface show interface') do @echo %a %b
    Admin State
    -------------------------------------------------------------------------
    Enabled Connected
    Enabled Connected
    Enabled Connected
    Enabled Disconnected

    In case, if you want to additional string along with the variable.

    C:\Users\cyberkeeda>for /f "tokens=1,2" %a in ('netsh interface show interface') do @echo Boot Stats= %a Ethernet stat= %b


    Now in case, if you want to use further filter within it, below one liner can help you.

    C:\Users\cyberkeeda>netsh interface show interface | for /f "tokens=2" %a in ('findstr Wi-Fi') do @echo %a
    Connected




    Read more ...

    How to Create Windows 10 Bootable USB on Ubuntu or any Linux desktop



    Are you looking for any desktop application on Ubuntu to create a bootable pendrive/flash drive with Windows.

    WoeUSB is a simple tool that enable you to create your own usb stick windows installer from an iso image or a real DVD.


    WoeUSB  package contains two programs:
    • woeusb: A command-line utility that enables you to create your own bootable Windows installation USB storage device from an existing Windows Installation disc or disk image
    • woeusbgui: A GUI wrapper of woeusb based on WxWidgets


    So, lets know how install the WoeUSB on Ubuntu 
    Official & updated Installation and Github link : Here
    #    sudo add-apt-repository ppa:nilarimogard/webupd8
    #    sudo apt update
    #    sudo apt install woeusb
    In case if you wish to remove that woeusb PPA, remove it from the bellow command.
    #    sudo add-apt-repository --remove ppa:nilarimogard/webupd8
    #    sudo apt-update
    Now, WoeUSB has installed on my Ubuntu, though the interface is self explanatory still let's move ahead and know how to use it.

    Open WoeUSB application and choose the USB drive and your windows iso kept within your Ubuntu.
    Once you are done click install and you are done, you can monitor the progress on screen.


    In case you receive a error dialogue like below, follow the below steps

    Find your USB drive's mounted file system and block by running lsblk on terminal and find your device their.
    To filter, look for size of your USB or name of the USB drive, below screen shot gives the picture of my USB drive ( 8 GB ) size, and named as /dev/sdc
    #    lsblk

    So we will unmount that partition out of the system.
    Notice there  /dev/sdc is the full size of my USB disk, but the data is witten on it's /dev/sdc1 partition.
    My USB disk is  /dev/sdc, ensure your USB is unmounted with the following command. Replace /dev/sdc1 with your own partition name.
    #    sudo umount /dev/sdc1
    Now try again from the   WoeUSB desktop application.
    In case if you are willing to do the same through woeusb CLI utility, here is the way.
    #    sudo woeusb -v --device /home/kunal/windows-10.iso /dev/sdc
    /home/kunal/windows-10.iso  :  Replace it with your iso location.
    /dev/sdc : replace it with your USB drive ( check it from lsblk )
    Read more ...

    PIP SSL eeror while installing : SSLError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:579)


    If you too, have encountered SSL errors while installation/upgrading any python package from pip.
    Here below is the workaround for it.


    You might be flooded by this errors.
    Retrying (Retry(total=1, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError(SSLError(1, u'[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed 
    SSLError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:579) 

    Workaround.

    Ignore SSL errors by setting pypi.org and files.pythonhosted.org as trusted hosts.
    #  pip install --trusted-host pypi.org --trusted-host files.pythonhosted.org <package_name>
    Lets assume i want to install pika through pip 
    #  pip install --trusted-host pypi.org --trusted-host files.pythonhosted.org pika
    Read more ...
    Related Posts Plugin for WordPress, Blogger...
    Designed By Kunal Saha