Search This Blog

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

/etc/yum.repos.d/ 

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

[dockerrepo]
name=Docker Repository
baseurl=https://yum.dockerproject.org/repo/main/fedora/23
enabled=1
gpgcheck=1
gpgkey=https://yum.dockerproject.org/gpg


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

authorized_keys 
 
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@175.17.0.2

where 2221 is ssh port & 175.17.0.2 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.