Docker – Basic Cheat Sheet

docker.com

docker.com

As a learning curve, I had marked Docker in my list

So just tipping some quick commands for your and my own reference as it is not a primary tool I am using day-to-day

Display Docker Images:

$ docker images

Run Docker Image:

$ docker run hello-world

Note: If you do not have an image in your local machine, docker will look into docker hub (over the internet)

Write a docker file:

$ mkdir dockerfolder

$ cd dockerfolder

$ vim newdockerfile

RUN apt-get -y update && apt-get install -y telnet

save and close your newdockerfile “wq!”

Build and image from our Docker File

$ docker build -t telnet-install .

Note: we are using a period in the end of docker build command to represent the newdockerfile within the directory

If you want to run new build file: “docker run telnet-install”

Tag your image-id: (required if you want to push to docker hub)

$ docker tag 693bce725149 terminaltolinux/telnet-install:latest

Note: image id can be found from “docker images” command

Login to docker hub:

$ docker login –username=terminaltolinux –email=terminal@linux.com

Note: after docker login command it will prompt for password, prior have a docker hub account

Push docker image to docker hub account:

$ docker push terminaltolinux/telnet-install

Note: Verify from docker hub account, the docker image will be pushed. Prior create a repo on docker hub

Delete a docker image:

$ docker rmi -f terminaltolinux/telnet-install

Pull docker image from docker hub account:

$ docker run terminaltolinux/telnet-install

Note: it will not find in the local machine as we deleted earlier and will fetch it online and run it, however “docker pull terminaltolinux/telnet-install” can also be used to just pull the image.

Search docker image:

$ docker search mysql

Search docker image with number of stars:

$ docker search -s 1 mysql

Run docker image in background:

$ docker run -d mysql

Run docker image with interactive session:

$ docker run -it ubuntu

List running containers

$ dockers ps

Inspect a container

$ docker inspect <container-id>

Note: container-id will be available from “docker ps”

Logs of standard error or standard out

$ docker log <container-id>

Commit changes to container and save as a separate image. (tag it):

$ docker commit <container-id> nginx-ubuntu

Port binding to container

$ docker run -d -p 6379 reds

Note: -p binds port but if we wanted to map this port directly on the host, we will use the option -p 6379:6379 and if with particular ip then -p 127.0.0.1:6379:6379

Binding directories

$ docker run -d -v “/home/docker/data”:/data reds

Start a container

$ docker start <container-id>

Stop a container

$ docker stop <container-id>

Remove an exited container

$ docker rm <container-id>

Restart a container

$ docker restart <container-id>

Use docker with proxy:

If you want to run docker with environment proxy, edit /etc/default/docker amend your entry for http_proxy

TIP:

If we don’t tell docker explicitly we want to map port, it will block access through that port (because containers are isolated until you tell them you want access)

ANSIBLE 2.0.2.0 – Basic Cheat Sheet – CentOS 6

Ansible,com

Ansible.com

To install Ansible:

# wget http://download.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpminstall epel-release

# yum install epel-release-6-8.noarch.rpm

# yum update

# yum install ansible -y

Add remote hosts:

$ vim /etc/ansible/hosts

192.168.0.1 (your remote server IP) or
hostname.hostname.local (your remote server hostname)

Ping remote hosts: (if using ssh keys for authentication –ask-pass is not required)

$ ansible all -m ping –ask-pass

Ping remote hosts with specific account: (if using ssh keys for authentication –ask-pass is not required)

$ ansible all -m ping –ask-pass -u root

Execute command on remote server shell:

$ ansible all -m shell -a “mkdir /home/ansible/testdirectory” –ask-pass -u root

Remove file from remote server:

$ ansible all -m file -a “dest=/tmp/test.sh state=absent” –ask-pass -u root

Install apache on remote server:

$ ansible all -m yum -a “name=httpd state=latest” -u root

Change file permissions:

$ ansible all -m file -a “dest=/home/ansible/testfile.txt mode=600 owner=ansible group=anisble”

Confirm if package installed but do not update

$ ansible all -m yum -a “name=telnet state=present”

Confirm package is latest version

$ ansible all -m yum -a “name=telnet state=latest”

Confirm package is not installed

$ ansible all -m yum -a “name=telnet state=absent”

Start service

$ ansible all -m service -a “name=httpd state=started”

Restart service

$ ansible all -m service -a “name=httpd state=restarted”

Stop serivce

$ ansible all -m service -a “name=httpd state=stopped”

 

Gathering Facts

$ ansible all -m setup

Distribute Linux flavors in Ansible host file:

$ vim /etc/ansible/hosts

[RHEL]
192.168.1.1
rhel.redhat.test
[SUSE]
192.168.1.2
suse.opensuse.test

Only send instructions on RHEL hosts:

$ ansible RHEL  -m shell -a “mkdir /home/ansible/testfolder” 

Ansible use YaML for Automation and known as Playbook in Ansible

create a playbook i.e an .yaml file eg: telnetPlaybook.yaml


– hosts: SUSE
remote_user: root
tasks:
– zypper: name=telnet state=latest
– hosts: RHEL
remote_user: root
tasks:
– yum: name=telnet state=latest

Run playbook with Ansible: (-f switch allow the execution to be performed on multiple hosts parallel)

$ ansible-playbook telnetPlaybook.yaml -f 10

Ansible Modules (-m): These are few but there is huge list.

command – execute commands and this is default module of Ansible.
copy – copy files
shell – use remote shell to execute
file – file operations
ping – ping remote hosts
yum – Redhat package manager
git – use GIT
user – user creation, manipulation
service – manage services

If you find it interesting, spread the word 🙂

Add static proxy as Env Variable in CentOS / RedHat

PROXY

PROXY

My office environment like many others are providing us Internet via proxy, on Windows Machine/Servers as they are part of domain the policy is pushed and as you login with your domain account you will find it available.

However on Linux servers I always go ahead with doing the following:

export http_proxy=http://proxy.blah.blah:80

And whenever the servers were required to reboot the proxy used to wipe out.

This time I made sure to make it static and plan to push it via Ansible to all the Linux babies I love.

Logged in from root account:

vim /etc/environment
http_proxy=http://proxy.blah.blah:80

Save the file – Re-initialize the shell or logout and login back. You will not have to re-add it back again.

To verify the variable

echo $http_proxy

How to Change Font Colors in CentOS / RedHat

Red & Turquoise Terminal

Red & Turquoise Terminal

One of my monitor display was bothering my eyes, therefore I decided to change the colors being displayed on the monitor I am using, especially for the directory as it was dark blue and I had to dig myself inside the screen to actually read in that color. (my eyes are not week but I love small fonts)

I was not sure how to do it but knew it can be changed as I studied them long time ago, did some research and found out there are multiple ways to perform it.

As my environment is an Ansible lab therefore it did not click me to just change it for a specific user therefore I changed in environment base:

This is what I did: (from root user)

vim /etc/DIR_COLORS
DIR 01;96

Just above DIR value, I found out FILE parameter but it was commented, so i edited it to

vim /etc/DIR_COLORS
FILE 01;91

Now my terminal is displaying 96  = turquoise as DIR and 91  = light red as FILE and I like it !!

For you reference color codes:

0 = default colour
1 = bold
4 = underlined
5 = flashing text
7 = reverse field
31 = red
32 = green
33 = orange
34 = blue
35 = purple
36 = cyan
37 = grey
40 = black background
41 = red background
42 = green background
43 = orange background
44 = blue background
45 = purple background
46 = cyan background
47 = grey background
90 = dark grey
91 = light red
92 = light green
93 = yellow
94 = light blue
95 = light purple
96 = turquoise
100 = dark grey background
101 = light red background
102 = light green background
103 = yellow background
104 = light blue background
105 = light purple background
106 = turquoise background

I did not try it but if you are interested in changing it for specific user you can try this:

cp /etc/DIR_COLORS to $HOME/.dir_colors

once copied, edit you local copy i.e .dir_colors and play with it.

Don’t forget you need to re-initialize the shell or logout and login back for changes to take affect.

Install iftop, htop and NetHogs on RHEL / CentOS 6.x x86_64 [Internet Required]

Recently I was given a task to create two CentOS 6.5 Jump Servers in the environment I am working currently.

There was a specific requirement for the following packages.

  • iftop – Network Bandwidth Monitoring
  • htop – Linux Process Monitoring
  • NetHogs – Monitor per process Network Bandwidth

We have an internal secure proxy server via which Internet was easily available for my servers. This is how I did:

Step 1 – Enable EPEL (Extra Packages for Enterprise Linux) and install rpm

cd /tmp

wget http://download.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm

rpm -ivh epel-release-6-8.noarch.rpm

Step 2 – Verify EPEL Repo

yum repolist

(it should display EPEL repo in the output)

Step 3 – Install packages

yum -y install iftop

yum -y install htop

yum – y install NetHogs

Note: Just in case you face the following error:

yum error “Cannot retrieve metalink for repository: epel. Please verify its path and try again”

You will have to edit the following repo’s by commenting entries ‘mirrorlist=..’ and un-comment entries ‘baseurl=…’

  • /etc/yum.repos.d/epel.repo
  • /etc/yum.repos.d/epel-testing.repo

How to install and configure sudo in Solaris Sparc 10

Sudo Vision

Sudo Vision

First you need following packages to install

gcc-3.4.6-sol10-sparc-local.gz
libiconv-1.13.1-sol10-sparc-local.gz
libintl-3.4.0-sol10-sparc-local.gz
sudo-1.7.2p5-sol10-sparc-local.gz

Install with following command

pkgadd -d downloadPath/filename

If you are unable to find sudo package online, your Solaris Sparc Companion disk contains it

Directory in Solaric Sparc Companion disk which contain sudo is “SFWsudo”

If I assume your path to package is /cdrom/Solaris_sparc/sparc/components/SFWsudo

Install by following command

pkgadd –d /cdrom/Solaris_sparc/sparc/components/  SFWsudo

After your installation is complete

First find the path of binary and configuration files, following is my example:

grep sudoers /var/sadm/install/contents

/opt/sfw/etc/sudoers f none 0440 root root 589 50133 1104945433 SFWsudo
/opt/sfw/man/man4/sudoers.4 f none 0444 root bin 57547 31697 1104945433 SFWsudo
/usr/local/share/vim/vim73/ftplugin/sudoers.vim f none 0644 bin bin 426 36373 1285497623 SMCvim
/usr/local/share/vim/vim73/syntax/sudoers.vim f none 0644 bin bin 19276 64681 1285497623 SMCvim 

Now my I can see that my configuration file i.e. sudoers is in /opt/sfw/etc/sudoers and for sudo it is always in the same path but in /bin directory i.e. /opt/sfw/bin/sudo

Steps for sudo to work properly:

  1. Add /opt/sfw/bin  in your PATH if it is not available – check with echo $PATH
  2. Sudoers file default permission will be read only, for making changes you will need to first change the permission of sudoers file and edit your changes and revert back the permission of sudoers file to (chmod 440)
  3. Sudo binary which is in /opt/sfw/bin should have the sticky bit set permission i.e. (chmod u+s )

And you are done here, enjoy and start using sudo

CrossOver: Run MsOffice / MsOutlook On Linux And Mac

CrossOver: Run MsOffice / MsOutlook On Linux And Mac

You have to pay a cost to get a Windows Operating System license whereas for Linux it is free; switching operating system is not an easy task with reference to years of experience over a single platform. But in recent years Ubuntu Linux have developed good amount of users running their OS. Microsoft Office is a major concern in the industry for users to revamp their thinking and divert their self to adopt another Operating System, everything takes time and now we have fully functional MsOffice / MsOutlook available.

A well-known program Wine is already available but numerous bug fixes are required, when it comes to install or configure MsOffice / MsOutlook therefore CrossOver; a project with collaboration of Wine is a much more matured, because everything developed at CrossOver revolves around Wine.

The matured products are usually priced, as it is an open-source development the cost is very minimal and initially you get a 14 days trail to test your product. They usually provide a free copy in offers for a limited time so you have to be updated what’s coming next from them.

Let us install it on Ubuntu 12.04 32 bit OS to see how handy the tool is.

Double click on the downloaded .deb file and Ubuntu Software Center will take care of it. Click Install and wait for the installation to complete.

Installer

Now, CrossOver is installed and ready to install a Windows application. Find it in Applications > CrossOver > Install Windows Software

Install Windows Application

Click Install Windows Software and CrossOver Software Installer will pop up, A list of supported applications will be viewed. The applications which can be downloaded directly from web will be installed by CrossOver just by selecting Supported Applications items under the list, whereas in our case it is MsOffice and a licensed product therefore executable should be provided.

Select the Application from the Supported List.

Choose Office 2007

Now provide the executable to the installer, which by default will install in winxp bottle. Bottles are the containers of application for binaries management.

Choose Installer

Now, click Install and CrossOver will start installing your desired application.

Note: Connectivity to internet is required as several backend dependencies with reference to application are being downloaded and executed in background in order to run the application.

Installation Started

After the installer resolves all the dependencies in order to start installing the core application a pop window of executable installing will be prompt just as it happens in any Windows OS.

Office Installation

Wait till the installation finish and you are ready to use your application. Your installed application will be available in Applications > Windows Applications > Microsoft Office

Installed ScreenShot

CrossOver is a product of CodeWeavers and providing excellent services since 1996, obtaining a license will not only provide you the complete version of CrossOver but also support for your desired application and troubleshooting will be entertained on priority basis either by generating a ticket or phone call support.

Download your free trail by registering your name and email address, and install the .deb file for Ubuntu users with reference to 32 bit or 64 bit both available. For Red Hat Enterprise Linus or CentOS users .rpm is also available and similarly a respective installation file for Mac Users

HowTo configure Telnet on Linux (Redhat)

Telnet

Telnet

Re-blogged from Zahidhaseeb’s Blog:

In my environment I have used Linux Redhat 6.2

  • Install three packages telnet-server, telnet and xinetd.
  • Make sure that the xinetd service should be running.
  • Configure the file name /etc/xinetd/telnet

1.) Install three packages telnet-server, telnet and xinetd.

You need to install three services

for example # yum install telnet-server telnet
the above command will also install the xinetd service. See the following example for reference:

Dependencies Resolved

=====================================================
Package               Arch         Version                  Repository    Size
=====================================================
Installing:
telnet                i686         1:0.17-47.el6            base          56 k
telnet-server         i686         1:0.17-47.el6            base          36 k
Installing for dependencies:
xinetd                i686         2:2.3.14-33.el6          base         121 k

Transaction Summary
=====================================================
Install       3 Package(s)

Total download size: 213 k
Installed size: 409 k

2.) Make sure that the xinetd service should be running.

# service xinetd status
xinetd (pid  13561) is running…

Please also note: Make sure that your firewall also stopped or the telnet traffic is allowed

3.) Configure the file name /etc/xinetd.d/telnet

We need to change the following highlighted line from yes to no

# vi /etc/xinetd.d/telnet
# default: on
# description: The telnet server serves telnet sessions; it uses \
#    unencrypted username/password pairs for authentication.
service telnet
{
flags        = REUSE
socket_type    = stream
wait        = no
user        = root
server        = /usr/sbin/in.telnetd
log_on_failure    += USERID
disable        = yes
}

Note:

In few scenarios, telnet works over the ip, but does not resolve specific ports. In that case xinetd services needs a restart

“service xinetd restart”

Convert RHN repositories (yum) with RHEL Media DVD repository

yum

repositories (yum)

Re-blogged from Zahidhaseeb’s Blog:

Step # 1

# pwd
/etc/yum.repos.d

Step # 2

# vi rhel-source.repo

Step # 3
You may see a result like below

[rhel-source]
name=Red Hat Enterprise Linux $releasever – $basearch – Source
baseurl=ftp://ftp.redhat.com/pub/redhat/linux/enterprise/$releasever/en/os/SRPMS/
enabled=0
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-release

[rhel-source-beta]
name=Red Hat Enterprise Linux $releasever Beta – $basearch – Source
baseurl=ftp://ftp.redhat.com/pub/redhat/linux/beta/$releasever/en/os/SRPMS/
enabled=0
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-beta,file:///etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-release

Step # 4

Add the below lines on the top of file above

[Media]
name=RHELmedia
baseurl=file:///media/RHEL_6.2\ x86_64\ Disc\ 1/Server/
enabled=1
gpgcheck=0

Please Note: Keep enabled=1 for [Media] and mark enabled=0 for[rhel-source-beta] and [rhel-source] .

Conclusion

Now you will be able to use yum command and the request will redirect to the DVD media of Redhat which you inserted in the CD/DVDrom (instead of going to internet/RHN)

Helpful Link

http://blog.sriunplugged.com/linux/adding-redhat-dvd-as-repository/

LVM / Logical Volume Manager

LVM / Logical Volume Manager

LVM / Logical Volume Manager

It can be said as a thin software layer on top of the hard drives and partitions, which creates illusion of continuity and easy of use for managing hard drives replacement, re-partitioning and backups.

It’s common usages are to manage large drives farm by adding a disk, replacing a disk, copy and share the disks without interrupting services running. For small setups there is no need to worry about partition size offering for requirements in future as disks partition can be re-sized easily on run-time, further making backups by taking snapshots and creating single logical volume of multiple physical volumes or entire hard disks functionality is also available.

Features of LVM

  • Re-size volume groups
  • Re-size logical volumes
  • Create read-only snapshot – LVM1
  • Create read-write snapshot – LVM2
  • Strips whole or parts of logical volumes (similar Raid0)
  • Mirror whole or parts of logical volumes (similar Raid1)
  • Move online logical volumes
  • Split or merge volume groups

Almost features can be performed online without disrupting users.