This Blog is to share our knowledge and expertise on Linux System Administration and VMware Administration

Friday, January 26, 2018

Working with Docker Container - Creating an account with Docker Hub

Friday, January 26, 2018 0

Creating an account with Docker Hub

Docker Hub is like GitHub for images. It is a public registry on which you can host images both public and private, share them and collaborate with others. It has integration with GitHub, Bitbucket, and can trigger automated builds.

As of now, the creation of an account on Docker Hub is free. A repository can hold different versions of an image. You can create any number of public repositories for your images. By default, you will have one private repository, which will not be accessible to the public. You can buy more private repositories. You can create an account either through a web browser or from the command line.

To create an account through a web browser on Docker Hub, visit https://hub.docker.com/account/signup/ and create an account:
 

Give the required details & and get created docker login.

To create an account using the command line, run the following command and submit the required details:
root@Docker:~# docker login
Login with your Docker ID to push and pull images from Docker Hub. If you don't have a Docker ID, head over to https://hub.docker.com to create one.
Username (nskselvan):
Password:

Thursday, January 25, 2018

How to extend the windows server disk space in command line

Thursday, January 25, 2018 0

Extending the windows server disk space in command line

Once the disk space added from storage to windows server.

Here, C drive is 75G and need to extend 25 GB. So total 100GB.

Go to command prompt and type disk part.


C:\Users\nsk>diskpart

C:\Users\nsk>

It will open a separate windows. Then follow the below steps to extend the C drive from 75GB to 100GB  (adding 25 GB)

Microsoft DiskPart version 6.1.7601
Copyright (C) 1999-2008 Microsoft Corporation.
On computer: TESTSERVER

DISKPART> list disk

  Disk ###  Status         Size          Free     Dyn  Gpt
  --------  -------------       -------         -------    ---   ---
  Disk 0    Online         75 GB        25 GB
  Disk 1    Online         6144 MB  1024 KB
  Disk 2    Online         12 GB       1024 KB
  Disk 3    Online         100 GB     1024 KB
  Disk 4    Online         225 GB       224 GB

DISKPART> select disk 0

Disk 0 is now the selected disk.

DISKPART> list part

  Partition ###  Type                 Size       Offset
  -------------  ----------------          -------     -------
  Partition 1    Primary            100 MB  1024 KB
  Partition 2    Primary              49 GB   101 MB

DISKPART> select part2

Microsoft DiskPart version 6.1.7601

DISK              - Shift the focus to a disk. For example, SELECT DISK.
PARTITION   - Shift the focus to a partition. For example, SELECT PARTITION.
VOLUME       - Shift the focus to a volume. For example, SELECT VOLUME.
VDISK           - Shift the focus to a virtual disk. For example, SELECT VDISK.

DISKPART> select part 2

Partition 2 is now the selected partition.

DISKPART> extend

DiskPart successfully extended the volume.

DISKPART> list disk

  Disk ###  Status           Size          Free          Dyn  Gpt
  --------  -------------         -------          -------            ---  ---
* Disk 0    Online           75 GB         0 B
  Disk 1    Online         6144 MB      1024 KB
  Disk 2    Online           12 GB         1024 KB
  Disk 3    Online          100 GB        1024 KB
  Disk 4    Online          225 GB         224 GB

DISKPART>

Hope it helps.

Monday, January 22, 2018

ss command in RHEL7 and examples

Monday, January 22, 2018 0

ss command in RHEL7 


NAME
       ss - another utility to investigate sockets
   
ss is used to dump socket statistics. It allows showing information similar to netstat.  It can display more TCP and state informations than other tools.
When no option is used ss displays a list of open non-listening sockets (e.g. TCP/UNIX/UDP) that have established connection.

[root@nsk ~]# ss -tpna | grep -i 25
LISTEN     0      100    127.0.0.1:25       *:*     users:(("master",pid=1198,fd=13))
LISTEN     0      100               ::1:25       :::*    users:(("master",pid=1198,fd=14))

Here,
-t, --tcp  Display TCP sockets
-p, --processes Show process using socket
-n, --numeric Do not try to resolve service names
-a, --all Display both listening and non-listening (for TCP this means established connections) sockets

SS command example:

Display all TCP sockets
[root@nsk ~]# ss -t -a
State       Recv-Q Send-Q    Local Address:Port        Peer Address:Port
LISTEN      0      128                  *:ssh                         *:*
LISTEN      0      100           127.0.0.1:smtp              *:*
ESTAB       0       0               10.0.2.15:ssh        10.0.2.2:56004
ESTAB       0       0               10.0.2.15:ssh        10.0.2.2:55714
LISTEN      0      128                 :::ssh                        :::*
LISTEN      0      100                ::1:smtp                            :::*
[root@nsk ~]#                                    

Display all TCP sockets with process SELinux security contexts
[root@nsk ~]# ss -t -a -Z
State       Recv-Q Send-Q    Local Address:Port   Peer Address:Port
LISTEN      0      128                   *:ssh              *:*          users:(("sshd",pid=966,proc_ctx=system_u:system_r:sshd_t:s0-s0:c0.c1023,fd=3))
LISTEN      0      100           127.0.0.1:smtp              *:*          users:(("master",pid=1198,proc_ctx=system_u:system_r:postfix_master_t:s0,fd=13))
ESTAB       0       0               10.0.2.15:ssh        10.0.2.2:56004     users:(("sshd",pid=1329,proc_ctx=unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023,fd=3))
ESTAB       0       0               10.0.2.15:ssh        10.0.2.2:55714     users:(("sshd",pid=1263,proc_ctx=unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023,fd=3))
LISTEN      0      128                  :::ssh              :::*          users:(("sshd",pid=966,proc_ctx=system_u:system_r:sshd_t:s0-s0:c0.c1023,fd=4))
LISTEN      0      100                 ::1:smtp            :::*          users:(("master",pid=1198,proc_ctx=system_u:system_r:postfix_master_t:s0,fd=14))

Display all UDP sockets
[root@nsk ~]# ss -u -a
State       Recv-Q Send-Q   Local Address:Port      Peer Address:Port
ESTAB       0      0            10.0.2.15:42417    198.55.111.50:ntp
ESTAB       0      0            10.0.2.15:39451    66.135.44.92:ntp
ESTAB       0      0            10.0.2.15:50903    198.60.22.240:ntp
ESTAB       0      0            10.0.2.15:51175    198.58.105.63:ntp
UNCONN      0      0                    *:bootpc              *:*
UNCONN      0      0                    *:42307                *:*
UNCONN      0      0            127.0.0.1:323            *:*
UNCONN      0      0                   :::42236                :::*
UNCONN      0      0                  ::1:323          :::*
                                                  
Display all established ssh connections.
[root@nsk ~]# ss -o state established '( dport = :ssh or sport = :ssh )'
Netid Recv-Q Send-Q      Local Address:Port       Peer Address:Port  
tcp   0      0               10.0.2.15:ssh           10.0.2.2:56004  timer:(keepalive,117min,0)
tcp   0      0               10.0.2.15:ssh           10.0.2.2:55714  timer:(keepalive,110min,0)
                                                           
For more infor, please refer man ss.

Sunday, January 21, 2018

Working with Docker Container - Setting the restart policy on a container

Sunday, January 21, 2018 0

Setting the restart policy on a container

Restart policy is added with the run command with flags to specify the restart policy. With this policy, we can configure containers to start at boot time. This option is also very useful when a container dies accidentally.

Syntax:docker run --restart=POLICY [ OPTIONS ]  IMAGE[:TAG]  [COMMAND]  [ARG...] 

root@Docker:~# docker run --restart=always -d -i -t centos /bin/bash
fb83a04222c73d0e80f84103d4fe58c3ccd95e4a44b39386a937427bda2ad465

Options: 
no            : This does not start the container if it dies
on-failure : This restarts the container if it fails with nonzero exit code
always     : This always restarts the container without worrying about the return code

You can also give an optional restart count with the on-failure policy as follows:

root@Docker:~# docker run --restart=on-failure:3 -d -i -t centos /bin/bash
96b07463e85f3452cbbbf0de1298d4311634efef20f60a1d164e18f83ea19e15

For help with the docker run use --help

Saturday, January 20, 2018

Working with Docker Container - Accessing the host device inside the container

Saturday, January 20, 2018 0

Accessing the host device inside the container

 we can give access of the host device to a container with the --device option to the run command. Earlier, one has bind mount it with the -v option and that had to be done with the --privileged option.

Syntax :
     docker run --device=<Host Device>:<Container Device Mapping>:<Permissions>   [ OPTIONS ]  IMAGE[:TAG]  [COMMAND]  [ARG...]

#docker run --device=/dev/sdc:/dev/xvdc -i -t centos /bin/bash


The preceding command will access /dev/sdc inside the container.

For help with the docker run use --help

Friday, January 19, 2018

Working with Docker Container - Exposing a port while starting a container

Friday, January 19, 2018 0

Exposing a port while starting a container

There are a number of ways by which ports on the container can be exposed. One of them is through the run command, which we will cover in this chapter. The other ways are through the Docker file and the --link command.

Syntax:  docker run --expose=PORT [ OPTIONS ]  IMAGE[:TAG]  [COMMAND]  [ARG...]

to expose port 22 while starting a container, run the following command:

root@Docker:~# docker run --expose=22 -i -t centos /bin/bash
[root@88a0e1ab48df /]#
root@Docker:~# docker ps
CONTAINER ID  IMAGE   COMMAND  CREATED          STATUS            PORTS       NAMES
88a0e1ab48df    centos     "/bin/bash"   27 seconds ago  Up 26 seconds   22/tcp  amazing_bohr

For help with the docker run use --help

Thursday, January 18, 2018

Working with Docker Container - Looking at the logs of containers

Thursday, January 18, 2018 0

Looking at the logs of containers

If the container emits logs or output on STDOUT/STDERR, then we can get them without logging into the container.

Syntax : docker logs  CONTAINER

root@Docker:~# docker logs centos
[root@6d65e303381c /]# uptime
 04:07:13 up  1:02,  0 users,  load average: 0.02, 0.01, 0.00
[root@6d65e303381c /]# hostname
6d65e303381c
[root@6d65e303381c /]# exit
root@Docker:~#

Docker will look at the container's specific log file from /var/lib/docker/containers/<Container ID> and show the result.

For help with the docker logs use --help

Working with Docker Container - Returning low level information about a container

Thursday, January 18, 2018 0

Returning low-level information about a container

While doing the debugging, automation, and so on, we will need the container configuration details. Docker provides the inspect command to get those easily.

To inspect a container/image, run the following command:
Syntax:
docker inspect [-f|--format="" CONTAINER|IMAGE [CONTAINER|IMAGE...]
We'll start a container and then inspect it:

root@Docker:~# docker run -id centos /bin/bash
c5f6ce3b5d2f82bb7a2bbc82b0b71bc2130ceb4caf163afbf5883cfbb150f256

root@Docker:~# docker inspect c5f6ce3b5d2f82bb7a2bbc82b0b71bc2130ceb4caf163afbf5883cfbb150f256

[
    {
        "Id": "c5f6ce3b5d2f82bb7a2bbc82b0b71bc2130ceb4caf163afbf5883cfbb150f256",
        "Created": "2018-01-02T12:18:18.232317934Z",
        "Path": "/bin/bash",
        "Args": [],
        "State": {
            "Status": "running",
            "Running": true,

    .........
    .........
}]

Docker will look into the metadata and configuration for the given image or container and present it.

With the -f | --format option we can use the Go (programming language) template to get the specific information. The following command will give us an IP address of the container:

root@Docker:~# docker inspect --format='{{.NetworkSettings.IPAddress}}' c5f6ce3b5d2f82bb7a2bbc82b0b71bc2130ceb4caf163afbf5883cfbb150f256
172.17.0.4

The following command will give us an Hostname Path of the container:

root@Docker:~# docker inspect --format='{{.HostnamePath}}' c5f6ce3b5d2f82bb7a2bbc82b0b71bc2130ceb4caf163afbf5883cfbb150f256
/var/lib/docker/containers/c5f6ce3b5d2f82bb7a2bbc82b0b71bc2130ceb4caf163afbf5883cfbb150f256/hostname

For help with the docker inspect use --help