Docker – Command line cheat sheet

Early post Docker for beginners ,we talked about how to start with dockers

Here are few basic commands which we need on daily base work case with docker

Useful Docker Commands helpful for operation

1) To Build Docker image from Dockerfile

      # docker build -t thegeeklinux:1.0 .
-t for Image name and tag name:tag (If you will not give tag it will tag latest)

2) To list images :
      # docker images

3) To save docker image in tar file :
      # docker save -o /tmp/thegeeklinux.tar thegeeklinux:1.0

4) To delete docker image :
      # docker rmi -f thegeeklinux:1.0
-f forcefully

5) To load docker image from tarball :
      # docker load < /tmp/thegeeklinux.tar

6) To tag docker image :
      # docker tag thegeeklinux:1.0 localhost:5000/thegeeklinux:1.0

NOTE:localhost:5000 should be your private registry ip and port

7) To push image to private or public registry server
      # docker push localhost:5000/thegeeklinux:1.0

NOTE: replace localhost with your private registry hostname or ip.

8) To pull docker image for private or public registry

a) To pull image from private registry server
         # docker pull localhost:5000/thegeeklinux:1.0

NOTE :replace localhost with your private registry hostname or ip.

b) To pull image from public registry
         # docker pull ubuntu

Docker Container Operation

1) To RUN Docker container :
      # docker run -it thegeeklinux:1.0
-i interactive mode
-t attract terminal

      # docker run -d --name thegeeklinux -p 80:80 -h tgl -l "com.thegeeklinux=1.0" -e WORKDIR=/opt/thegeeklinux thegeeklinux:1.0

-d Detach it will run container in backgraund.
-e set environment for container
-h Hostname you can give hostname to container also
-l we can give label also to container for indentification.
-p we can open port to host from container
–name Name of the container

2) To Run command inside docker container
      # docker exec thegeeklinux ls

3) Login to container without ssh :
      # docker exec -it thegeeklinux bash

4) To check container list :
      # docker ps

5) To check container memory and cpu.
      # docker stats thegeeklinux

6) To copy contant from container to host machine or host machine to container
      # docker cp ./thegeeklinux.war tgl:/opt/tomcat/current/webapps/

7) To check container related logs :
      # docker logs -f thegeeklinux
-f It will follow log output

8) To commit container :
      # docker commit -p -a "" -m "commit message" tgl tgl:2.0
-a Author of the container
-m commit message
-p pause container during commit

9) To export container in compressed file
      # docker export -o /tmp/dockerexport.tar thegeeklinux

NOTE : export command will not export attached volume.

10) To get container information
      # docker inspect thegeeklinux

NOTE: it will give info in json format

To get ip addres of container
       # docker inspect -f {{.NetworkSettings.IPAddress}} thegeeklinux

To get mapped port to host :
       # docker inspect -f '{{(index (index .NetworkSettings.Ports "22/tcp") 0).HostPort}}' thegeeklinux

11) To Stop container:
      # docker stop thegeeklinux

12) To start container :
      # docker start thegeeklinux

13) To get container processes
      # docker top thegeeklinux

14) To rename the container :
      # docker rename thegeeklinux tgl

15) To restart container :
      # docker restart docker-scripts

16) To delete container :
      # docker rm -vf thegeeklinux
-v delete volume also
-f delete container forcely


Ceph with devstack – part-1

Today going to see how to integrate ceph with devstack and mapping ceph as backend for nova, glance, cinder.

Ceph is a massively scalable, open source, distributed storage system. Ceph is in the Linux kernel and is integrated with the OpenStack cloud operating system.


Setup Dev Environment

Install OS-specific prerequisites:

sudo apt-get update
sudo apt-get install -y python-dev libssl-dev libxml2-dev \
                        libmysqlclient-dev libxslt-dev libpq-dev git \
                        libffi-dev gettext build-essential

Exercising the Services Using Devstack

This session has only been tested on Ubuntu 14.04 (Trusty), if you don’t have create on Virtual box with 4GB RAM, 100 GB HDD.

Clone devstack:

# Create a root directory for devstack if needed
sudo mkdir -p /opt/stack
sudo chown $USER /opt/stack

git clone /opt/stack/devstack

We will run devstack with minimal local.conf settings required to enable ceph plugin along with nova & heat, disable tempest, horizon which may slow down other services  here your localrc file

# MISC #
#SERVICE_TOKEN = <this is generated after running>
# Reclone each time
# Enable Logging
## CEPH #
enable_plugin devstack-plugin-ceph
# DevStack will create a loop-back disk formatted as XFS to store the
# Ceph data.
# Ceph cluster fsid
# Glance pool, pgs and user
# Nova pool and pgs
# Cinder pool, pgs and user
# Cinder backup pool, pgs and user
# How many replicas are to be configured for your Ceph cluster
# Connect DevStack to an existing Ceph cluster
#Enable heat services
ENABLED_SERVICES+=,h-eng h-api h-api-cfn h-api-cw
#Enable Tempest
#ENABLED_SERVICES+=tempest’ inside ‘local.config

Now run

~/devstack$ ./

Devstack will clone with master & ceph will be enabled & mapped as backend for cinder, glance & nova with PG pool size 8, can create own size in multiples of 2 power like 64 as your wish.

Sit back a while to clone devstack and get result as like below


DevStack Component Timing
Total runtime 2169
run_process 26
apt-get-update 52
pip_install 99
restart_apache_server 5
wait_for_service 20
apt-get 1653
This is your host IP address:
This is your host IPv6 address: ::1
Keystone is serving at
The default users are: admin and demo
The password: admin


Check the health of ceph with root permission, see “HEALTH_OK”

pandy@malai:~/devstack$ sudo ceph -s
cluster 6f461e23-8ddd-4668-9786-92d2d305f178
health HEALTH_OK
monmap e1: 1 mons at {malai=}
election epoch 1, quorum 0 malai
osdmap e16: 1 osds: 1 up, 1 in
pgmap v24: 88 pgs, 4 pools, 33091 kB data, 12 objects
194 MB used, 7987 MB / 8182 MB avail
88 active+clean

Here you go, ceph is installed with devstack


Ceph Single Node Setup – Part I


Ceph’s software libraries provide client applications with direct access to the RADOS object-based storage system, and also provide a foundation for some of Ceph’s advanced features, including RADOS Block Device (RBD), RADOS Gateway, and the Ceph File System.

In this article, we going to see about single node setup of Ceph along with RADOS gateway, where MDS, CephFS are not practicing with openstack setup. Part I discuss about ceph installation and configuration on single node.

Lab Setup

We are going to do setup on top of virtual box by mounting three SATA HD for setting up Ceph, at the end of setup we will have

  • 1 Mon
  • 3 OSDs




Create VM on top of virtual box see here click,                 with minimum RAM size of  2 GB with minimum 100 GB hard disk, then create 3 SATA HD with decent size 25 GB each, see screenshot below (ceph -1.vdi, ceph-2.vdi, ceph-3.vdi)


Ceph Installation

Install Ceph repo key

wget -q -O- ‘; | sudo apt-key add –

Add the Ceph (jewel release) repo to your Ubuntu sources list.

echo deb trusty main | sudo tee /etc/apt/sources.list.d/ceph.list

Update & Install Ceph

sudo apt-get update && sudo apt-get install ceph-deploy

Make sure your user account is having “sudo” permission, if not create passwordless sudo user for ceph  & Verify permission

sudo useradd -m -s /bin/bash ceph

sudo passwd cephecho “ceph ALL = (root) NOPASSWD:ALL” | sudo tee etc/sudoers.d/ceph

sudo chmod 0440 /etc/sudoers.d/ceph

Switch to the newly created user

sudo su – ceph

Create RSA keypair and copy it to same host, in case of multimode setup have to copy this on destination nodes

ssh-copy-id ceph@malai

Below is shell script which do the complete installation of ceph in single node, can be found from my git page click, it will do below action

# A very minimal ceph install script, using ceph-deploy
set -x

# Creating a directory based on timestamp..not unique enough
mkdir -p ~/ceph-deploy/install-$(date +%Y%m%d%H%M%S) && cd $_

#Install ceph key
wget -q -O- ‘; | sudo apt-key add –

#install ceph by pointing release repo to your Ubuntu sources list.
echo deb trusty main | sudo tee /etc/apt/sources.list.d/ceph.list

#Check & remove existing ceph setup
ceph-remove () {
ceph-deploy purge $HOST
ceph-deploy purgedata $HOST
ceph-deploy forgetkeys

#Ready to update & install ceph-deploy
sudo apt-get update && sudo apt-get install -y ceph-deploy

#Deploy ceph
HOST=$(hostname -s)
FQDN=$(hostname -f)
ceph-deploy new $HOST

#Add below lines into ceph.conf, pool size for number of replicas of data
#Chooseleaf s required to tell ceph we are only a single node and that it’s OK to store the same copy of data on the same physical node
cat <<EOF >> ceph.conf
osd pool default size=2
osd crush chooseleaf type = 0
#Time to install ceph
ceph-deploy install $HOST

#Create Monitor
ceph-deploy mon create-initial

#Create OSD & OSD with mounted drives /dev/sdb /dev/sdc /dev/sdd
ceph-deploy osd prepare $HOST:sdb $HOST:sdc $HOST:sdd
ceph-deploy osd activate $HOST:/dev/sdb1 $HOST:/dev/sdc1 $HOST:/dev/sdd1

#Restribute config and keys
ceph-deploy admin $HOST

#Read permission to read keyring
sudo chmod +r /etc/ceph/ceph.client.admin.keyring

sleep 30

#Here we go, check ceph health
ceph -s

After running the above script, will get output as below

“health HEALTH_OK”

Say Bravo to yourself, done successfully.

In next part, will talk about Object storage gateway setup and configuration and later will map with Openstack Backend storage.







Openstack -Delete Error State Instances

Many of us known that while deleting VM, sometimes it will get stuck in error state, it may be of many reason, like issues in message queue, DB others,

As first way of troubleshooting people will do below steps


Delete by resetting the state of the VM

nova reset-state --active {uuid-of-instance}

Check its state by nova list or nova show {uuid-of-instance}

Then try to delete it using command

nova delete {uuid-of-instance}

OR doing the force-delete

nova force-delete {uuid-of-instance}


But still there few thingswhich  may persist your VM in error state, so I came up with remove the instance and all dependent records from the nova database and made it automated as below which removes all your dependent mapped volumes and delete instances and free your SG and others


echo "Enter your MySQL user"

echo "Enter your MySQL user password"

echo "Enter your MySQL host"

mysql -u$MYSQL_USER -p$MYSQL_PASSWD -h$MYSQL_HOST -e 'USE nova; DELETE FROM security_group_instance_association WHERE instance_id IN (SELECT id FROM instances WHERE vm_state = "error");'
mysql -u$MYSQL_USER -p$MYSQL_PASSWD -h$MYSQL_HOST -e 'USE nova; DELETE FROM block_device_mapping WHERE instance_id IN (SELECT id FROM instances WHERE vm_state = "error");'
mysql -u$MYSQL_USER -p$MYSQL_PASSWD -h$MYSQL_HOST -e 'USE nova; DELETE FROM instance_info_caches WHERE instance_id IN (SELECT uuid FROM instances WHERE vm_state = "error");'
mysql -u$MYSQL_USER -p$MYSQL_PASSWD -h$MYSQL_HOST -e 'USE nova; UPDATE fixed_ips SET allocated = 0 WHERE instance_id IN (SELECT id FROM instances WHERE vm_state = "error");'
mysql -u$MYSQL_USER -p$MYSQL_PASSWD -h$MYSQL_HOST -e 'USE nova; DELETE FROM instances WHERE vm_state = "error";'


Here we go !!


Openstack -Metering resource usage



In Openstack, Telemetry service provides user-level usage data which can be used for customer billing, system monitoring, or alerts. Data can be collected by notifications sent by existing OpenStack components, Can view resource usage in dashboard as well as in CLI.

Resource Usage via Dashboard

  1. Log in to the dashboard and select the admin project from the drop-down list.
  2. On the Admin tab, click the Resource Usage category.
  3. Click the:
    • Usage Report tab to view a usage report per tenant (project) by specifying the time period (or even use a calendar to define a date range).
    • Stats tab to view a multi-series line chart with user-defined meters. You group by project, define the value type (min, max, avg, or sum), and specify the time period (or even use a calendar to define a date range).

Usage statistics via Nova

Though telemetry services are coming up, nova is doing needful greatly, with nova can retrieve host usage statistics instantly.

Host Usage statistics

  • List the hosts and the nova-related services that run on them:

    $ nova host-list
    | host_name | service     | zone     |
    | devstack  | conductor   | internal |
    | devstack  | compute     | nova     |
    | devstack  | cert        | internal |
    | devstack  | network     | internal |
    | devstack  | scheduler   | internal |
    | devstack  | consoleauth | internal |
  • Get a summary of resource usage of all of the instances running on the host:

    $ nova host-describe devstack
    | HOST     | PROJECT                          | cpu | memory_mb | disk_gb |
    | devstack | (total)                          | 2   | 4003      | 157     |
    | devstack | (used_now)                       | 3   | 5120      | 40      |
    | devstack | (used_max)                       | 3   | 4608      | 40      |
    | devstack | b70d90d65e464582b6b2161cf3603ced | 1   | 512       | 0       |
    | devstack | 66265572db174a7aa66eba661f58eb9e | 2   | 4096      | 40      |

    The cpu column shows the sum of the virtual CPUs for instances running on the host.

    The memory_mb column shows the sum of the memory (in MB) allocated to the instances that run on the host.

    The disk_gb column shows the sum of the root and ephemeral disk sizes (in GB) of the instances that run on the host.

    The row that has the value used_now in the PROJECT column shows the sum of the resources allocated to the instances that run on the host, plus the resources allocated to the virtual machine of the host itself.

    The row that has the value used_max in the PROJECT column shows the sum of the resources allocated to the instances that run on the host.

Instance usage statistics

$ nova diagnostics ubuntu
| Property         | Value         |
| cpu0_time        | 1138410000000 |
| memory           | 524288        |
| memory-actual    | 524288        |
| memory-rss       | 591664        |
| vda_errors       | -1            |
| vda_read         | 334864384     |
| vda_read_req     | 13851         |
| vda_write        | 2985382912    |
| vda_write_req    | 177180        |
| vnet4_rx         | 45381339      |
| vnet4_rx_drop    | 0             |
| vnet4_rx_errors  | 0             |
| vnet4_rx_packets | 106426        |
| vnet4_tx         | 37513574      |
| vnet4_tx_drop    | 0             |
| vnet4_tx_errors  | 0             |
| vnet4_tx_packets | 162200        |

General usage per tenant:

$ nova usage-list
Usage from 2016-05-02 to 2016-06-30:
| Tenant ID                        | Instances | RAM MB-Hours | CPU Hours | Disk GB-Hours |
| 0eec5c34a7a24a7a8ddad27cb81d2706 | 8         | 240031.10    | 468.81    | 0.00          |
| 92a5d9c313424537b78ae3e42858fd4e | 5         | 483568.64    | 236.12    | 0.00          |
| f34d8f7170034280a42f6318d1a4af34 | 106       | 16888511.58  | 9182.88   | 0.00          |

Openstack Cinder backup & Restore

Cinder is the code name for the open source project to develop OpenStack Block Storage, the block-based storage component of the OpenStack platform for cloud computing.

Today we are going to see how to take backup & restore with back end storage either Ceph / LVM

For better lab practice clone devstack along with swift, cinder backup

Step 1:  Clone devstack

git clone

Step 2: Clone localrc contains cinder backup and swift

git clone

Step 3: Copy the localrc from devstack-cinder-backup to devstack

cp localrc.txt devstack/localrc

Step 4: Deploy devstack as non-root user


Step 5: Source with admin tenant

Source admin admin

Step 6:   Check installed service list, you can see cinder, swift

Step 7:  Run “Cinder service-list”


Step 8: Create Volume with 1GB

cinder create –display_name pandi 1

Step 9 : Create  backup

cinder backup-create b7223f13-fd5c-462b-9318-0c47b2a306f1

Step 10 : See the created backup

 cinder backup-list


Step 11 : List swift volumes backups will list the created backups from cinder & Restore the backup volumes as per below command

swift list volumebackups | grep 2014c866-5939-494d-ba26-2c78acfd0230

cinder backup-restore 2014c866-5939-494d-ba26-2c78acfd0230


See the above screenshocinder list

| ID | Status | Migration Status | Name | Size | Volume Type | Bootable | Multiattach | Attached to |

| b7223f13-fd5c-462b-9318-0c47b2a306f1 | available | – | pandy | 1 | lvmdriver-1 | false | False | |
| fc1c6f25-bde7-4f4b-aca8-05ad70fa1c1c | available | – | restore_backup_2014c866-5939-494d-ba26-2c78acfd0230 | 1 | lvmdriver-1 | false | False | |

Successfully created backup and restored in cinder as above

Here the Cinder.conf file changes under /etc/cinder

backup_swift_url =

default_volume_type = lvmdriver-1

enabled_backends = lvmdriver-1

backup_driver = cinder.backup.drivers.swift



backup_swift_url = http://localhost:8080/v1/AUTH_
backup_swift_auth = per_user
backup_swift_auth_version = 1
backup_swift_user = <None>
backup_swift_key = <None>
backup_swift_container = volumebackups
backup_swift_object_size = 52428800
backup_swift_retry_attempts = 3
backup_swift_retry_backoff = 2
backup_compression_algorithm = zlib


Note: If you are in JUNO use below url, which is later fixed in next versions

backup_swift_url = http://localhost:8080/v1/AUTH_"

TryStack -Play around Openstack

Welcome, In this article we are going to see how to play with Trystack – The Easiest Way To Try Out OpenStack.

OpenStack is an open-source software cloud computing platform. OpenStack is primarily used for deploying an infrastructure as a service (IaaS) solution like Amazon Web Service (AWS). In other words, you can make your own AWS by using OpenStack. If you want to try out OpenStack, TryStack is the easiest and free way to do it.


In order to try OpenStack in TryStack, you must register yourself by joining TryStack Facebook Group. The acceptance of group needs a couple days because it’s approved manually. After you have been accepted in the TryStack Group, you can log in TryStack.


Overview: What we will do?

In this post, I will show you how to run an OpenStack instance. The instance will be accessible through the internet (have a public IP address). The final topology will like:


As you see from the image above, the instance will be connected to a local network and the local network will be connected to internet.


Step 1: Create Network

Network? Yes, the network in here is our own local network. So, your instances will be not mixed up with the others. You can imagine this as your own LAN (Local Area Network) in the cloud.

  1. Go to Network > Networks and then click Create Network.
  2. In Network tab, fill Network Name for example internal and then click Next.
  3. In Subnet tab,
    1. Fill Network Address with appropriate CIDR, for example Useprivate network CIDR block as the best practice.
    2. Select IP Version with appropriate IP version, in this case IPv4.
    3. Click Next.
  4. In Subnet Details tab, fill DNS Name Servers with (Google DNS) and then clickCreate.

Step 2: Create Instance

Now, we will create an instance. The instance is a virtual machine in the cloud, like AWS EC2. You need the instance to connect to the network that we just created in the previous step.

  1. Go to Compute > Instances and then click Launch Instance.
  2. In Details tab,
    1. Fill Instance Name, for example Ubuntu 1.
    2. Select Flavor, for example m1.medium.
    3. Fill Instance Count with 1.
    4. Select Instance Boot Source with Boot from Image.
    5. Select Image Name with Ubuntu 14.04 amd64 (243.7 MB) if you want install Ubuntu 14.04 in your virtual machine.
  3. In Access & Security tab,
    1. Click [+] button of Key Pair to import key pair. This key pair is a public and private key that we will use to connect to the instance from our machine.
    2. In Import Key Pair dialog,
      1. Fill Key Pair Name with your machine name (for example Edward-Key).
      2. Fill Public Key with your SSH public key (usually is in ~/.ssh/ See description in Import Key Pair dialog box for more information. If you are using Windows, you can use Puttygen to generate key pair.
      3. Click Import key pair.
    3. In Security Groups, mark/check default.
  4. In Networking tab,
    1. In Selected Networks, select network that have been created in Step 1, for exampleinternal.
  5. Click Launch.
  6. If you want to create multiple instances, you can repeat step 1-5. I created one more instance with instance name Ubuntu 2.

Step 3: Create Router

I guess you already know what router is. In the step 1, we created our network, but it is isolated. It doesn’t connect to the internet. To make our network has an internet connection, we need a router that running as the gateway to the internet.

  1. Go to Network > Routers and then click Create Router.
  2. Fill Router Name for example router1 and then click Create router.
  3. Click on your router name link, for example router1, Router Details page.
  4. Click Set Gateway button in upper right:
    1. Select External networks with external.
    2. Then OK.
  5. Click Add Interface button.
    1. Select Subnet with the network that you have been created in Step 1.
    2. Click Add interface.
  6. Go to Network > Network Topology. You will see the network topology. In the example, there are two network, i.e. external and internal, those are bridged by a router. There are instances those are joined to internal network.

Step 4: Configure Floating IP Address

Floating IP address is public IP address. It makes your instance is accessible from the internet. When you launch your instance, the instance will have a private network IP, but no public IP. In OpenStack, the public IPs is collected in a pool and managed by admin (in our case is TryStack). You need to request a public (floating) IP address to be assigned to your instance.

  1. Go to Compute > Instance.
  2. In one of your instances, click More > Associate Floating IP.
  3. In IP Address, click Plus [+].
  4. Select Pool to external and then click Allocate IP.
  5. Click Associate.
  6. Now you will get a public IP, e.g., for your instance.

Step 5: Configure Access & Security

OpenStack has a feature like a firewall. It can whitelist/blacklist your in/out connection. It is called Security Group.

  1. Go to Compute > Access & Security and then open Security Groups tab.
  2. In default row, click Manage Rules.
  3. Click Add Rule, choose ALL ICMP rule to enable ping into your instance, and then clickAdd.
  4. Click Add Rule, choose HTTP rule to open HTTP port (port 80), and then click Add.
  5. Click Add Rule, choose SSH rule to open SSH port (port 22), and then click Add.
  6. You can open other ports by creating new rules.

Step 6: SSH to Your Instance

Now, you can SSH your instances to the floating IP address that you got in the step 4. If you are using Ubuntu image, the SSH user will be ubuntu.

That’s all, You can now do play around !! Enjoy !! Cheers !!