Sunday, September 11, 2016

Running Ubuntu headless in Fedora 23 on Docker

First we will add docker repository for Fedora 23 for that inside directory


add "docker.repo" file in which add following content.I use nano a simple command line text editor for it through root privileges.most of tutorial assumes root previlages on bash shell.

docker.repo” file should look like

name=Docker Repository

now we will update repository as follows

dnf update

lets install docker on our fedora machine

dnf install docker-engine

let’s enable docker service as follows

systemctl enable docker.service

need to start docker service as follows

systemctl start docker

we can check status of docker service is running or not using below command

systemctl status docker

Now we will install ubuntu image

docker pull ubuntu

once we pulled ubuntu image we can run it

docker run -it ubuntu
docker run -it ubuntu:latest /bin/bash

every time we run a image it creates new container we can see list of container using following command

docker ps -a

by the way to see list of pulled images we can use following command

docker images

once we have command prompt of container we can install some package that are useful in our quest

apt-get install nano

this will install nano command line text editor while below command will install subset of networking related tools that are suitable for docker container image

apt-get install -y inetutils-ping

we can check ip address of ubuntu server from fedora command prompt as follows

docker inspect e350390fd549

output of above command will be json string in which find a key "IPAddress" which will give us ip address of Ubuntu server running in docker,here ‘e350390fd549is container id that we can get by issuing docker ps -a or simply by looking at command prompt of ubuntu machine.

Adding new users

adduser sangram

adduser sagar

add user sangram to sudo group

usermod -aG sudo sangram

Install ssh server as follows

apt-get install openssh-server

modify setting of ssh demeon as follows.

Open config file

nano /etc/ssh/sshd_config

modify it to allow root login,X11 Forwarding,enable password authentication ,change port from default value to suitable value.check if DSA & RSA & Public key authentication is enabled or disabled check where it will look for password.There may be text similar to below

DSAAuthentication yes
RSAAuthentication yes
PubkeyAuthentication yes
AuthorizedKeysFile %h/.ssh/authorized_keys

change flags suitably.

create public ,private keys using either rsa & dsa

ssh-keygen -t rsa

it will create two files under .ssh dir in you home directory of current user (root),in same location create a file

and add content of public key to it.Now copy the private key to you Fedora machine convert it to suitable format using puttygen command

puttygen id_dsa  -O private-openssh -o my-openssh-key

restart ssh serverusing below command replace restart by start if not running.

 /etc/init.d/ssh restart

now from fedora machine try to run putty and provide private key in ssh auth change IP address to Ubuntu server ip address also check port is same as one in which ssh server is running.

From command prompt you can check it as follows

ssh -p 2221 root@

where 2221 is ssh port & is ip address of you ubuntu server.

Lets install virtual framebuffer & lightweight window manager (jwm) & vnc server as follows

apt-get install xvfb

apt-get install x11vnc

jwm is very small window manager for X server.we are using xdm instead of gdm or kdm,xdm is default for X server.
apt-get install jwm

apt-get install xterm

apt-get --reinstall install xfonts-base

to assign password to vnc login issue following command

x11vnc -storepasswd

it will ask for password & confirmation do not change location where password will be stored default location will be /etc/x11vnc.pass

we need to define display settings as follows

Xvfb -screen 0 800x600x16 -ac &

now we will launch window manger JWM as follows

DISPLAY=:0 jwm &

to view our Window manager lets start vnc server as follows

x11vnc -rfbauth /etc/x11vnc.pass -display :0

now from fedora machine launch VNC viewer say tiger VNC viewer in that put ip address of our Ubuntu server it will ask for vnc password provide one you will see JWM running.

you can save changes made in running container to same image or new image so that you can latter work further on this as follows

docker commit e350390fd549 nameofconatainer

wish you best of luck.In case i miss some step in between(as this is done over weekends) please correct me.

Wednesday, August 31, 2016

Linq - Group by into an array

LINQ has lot of capability that we seldom use.For example sometime we need to group a column into a string array or collection of some sort like say list based on another column.

Here I will demonstrate same into an array.

For purpose of demonstration I will create a class in some existing project

  public class KeyValue
        public string KeyCol { get; set; }
        public string ValueCol { get; set; }
Now I will create simple array of type 'KeyValue' just created.

  var wordList = new Model.DTO.KeyValue[] {
                new Model.DTO.KeyValue {KeyCol="key1", ValueCol="value1" },
                new Model.DTO.KeyValue {KeyCol="key2", ValueCol="value1" },
                new Model.DTO.KeyValue {KeyCol="key3", ValueCol="value2" },
                new Model.DTO.KeyValue {KeyCol="key4", ValueCol="value2" },
                new Model.DTO.KeyValue {KeyCol="key5", ValueCol="value3" },
                new Model.DTO.KeyValue {KeyCol="key6", ValueCol="value4" }

Lets build a linq query on this collection(Array).Query groups 'KeyCol' property based on 'ValueCol' into group 'g' i.e. means g is collection of 'KeyCol'

            var query =from m in wordList
                     group m.KeyCol by m.ValueCol into g
                     select new { Name = g.Key, KeyCols = g.ToList().ToArray<string>() };

You can check resultset my looping  'query' 

    foreach (var rec in query)
        var name = rec.Name;
        var strArray = rec.KeyCols;

e.g in loop above when 'name' becomes 'value1' ,'strArray' will have value string[]{'key1','key2'} and so on.

we can further generalize this query to create object array in group by.