Shantanu's Blog

Corporate Consultant

July 21, 2016


Install and use private docker registry

# On the master server, create a registry container...
docker run -d -p 5000:5000 registry

This command will start a fresh new registry. If you have a registry with all your images built-in then use that like this...

docker run -p 5000:5000 -d shantanuo/myregistry

# On the client server, change the docker config file as shown below and restart docker...
vi /etc/sysconfig/docker
vi /etc/init.d/docker


vi /etc/default/docker


# Now download an image from docker hub and upload it to private repository...
docker pull django
docker pull rabbitmq:3-management
docker pull mongo:3.3.9
docker pull phusion/passenger-full
docker pull continuumio/miniconda

docker tag django
docker tag rabbitmq:3-management
docker tag mongo:3.3.9
docker tag phusion/passenger-full
docker tag continuumio/miniconda

docker push
docker push
docker push
docker push
docker push

# check if all the images are uploaded correctly
docker search
docker search localhost:5000/

# backup your private registry so that you can restore it in case of master server crash

docker commit 126781fc1667 shantanuo/myregistry

docker push shantanuo/myregistry

Download and run the private registry image from docker hub

docker run -p 5000:5000 -d shantanuo/myregistry

docker search localhost:5000/
openshift/busybox                     0
shantanuo/pyrun                       0
shantanuo/mydjango                    0
shantanuo/myrabbit                    0
shantanuo/mymongo                     0
shantanuo/mypassenger                 0
shantanuo/myminiconda                 0

Here is how to download and start a container from private registry...

From docker hub:

docker run --hostname oksoft -p 15672:15672  -d rabbitmq:3-management

From private registry:

docker run --hostname oksoft -p 15672:15672  -d



Install docker on Ubuntu Trusty 14.04

Steps to install docker on Ubuntu Trusty

sudo apt-get update

sudo apt-get install apt-transport-https ca-certificates

sudo apt-key adv --keyserver hkp:// --recv-keys 58118E89F3A912897C070ADBF76221572C52609D

vi /etc/apt/sources.list.d/docker.list

deb ubuntu-trusty main

sudo apt-get update

sudo apt-get purge lxc-docker

apt-cache policy docker-engine

sudo apt-get update

sudo apt-get install linux-image-extra-$(uname -r)

sudo apt-get install apparmor

sudo apt-get update

sudo apt-get install docker-engine

sudo service docker start

Labels: ,

July 12, 2016


tokuDB (mongo) using docker

Here is the command that will initiate a toku container.

docker run -d -p 27017:27017 -v /tokudata:/data/db ankurcha/tokumx

(or use official image "mongo" instead of ankurcha/tokumx to install mongoDB without toku engine)
Now this toku installation is available through port 27017 from host IP that may be and you can find it using ifconfig command.

The following python code will connect to the toku mongo container and add a record.

from pymongo import MongoClient
client = MongoClient('')
db = client.myFirstMB
db.countries.insert_one({"name" : "USA"})
for i in db.countries.find():
    print i

Since we have linked the data directory to /tokudata folder of the host machine, the data can be easily backed up.

Labels: ,

June 30, 2016


list of useful containers

Here is a list of some of the containers those I use frequently. Here is how to install docker
First make sure that you are a root user. And there is enough disk space available.

# install docker
yum install -y docker

# start docker
vi /etc/sysconfig/docker-storage

DOCKER_STORAGE_OPTIONS="--storage-opt dm.basesize=200G"

/etc/init.d/docker start

# Install docker-compose
curl -L`uname -s`-`uname -m` > /usr/local/bin/docker-compose
chmod +x /usr/local/bin/docker-compose

Editing storage options above will allow bigger containers (upto 200 GB) to be loaded. The container may get out of space once you start saving data into it.


In order to use node application within docker environment, you can use the official node image that can be found here...

Change to the directory where you have already written code and add the dockerfile with these 2 lines...

$ vi Dockerfile
FROM node:4-onbuild

Once your script is ready, you need to build an image...

$ docker build -t shantanuo/my-nodejs-app .

And run the node application...

$ docker run -p 8888:8888 -d shantanuo/my-nodejs-app

You can push this image to docker hub as a private or public repository.

docker login

docker push shantanuo/my-nodejs-app


ofifical mysql repository

mkdir -p /storage/test-mysql/datadir
docker run -d -p 3306:3306  -e MYSQL_ALLOW_EMPTY_PASSWORD=yes  -v /my/custom:/etc/mysql/conf.d  -v /storage/test-mysql/datadir:/var/lib/mysql   -v /my/custom:/etc/mysql/conf.d  mysql:5.6

(size: 100MB)
Just by changing the name to test-mysql2 we can set up another mysql container. Instead of mysql official version, we can use tutum/mysql which has customized installation.

fixed the bug in the official mysql image

Percona with tokuDB

docker run -e MYSQL_ALLOW_EMPTY_PASSWORD=yes -e INIT_TOKUDB=1 -d percona/percona-server

log in to the container and run this command to enable tokudb if "show engines" command does not show tokudb.

ps_tokudb_admin --enable

# backup of mysql hosted in the folder /storage of another container named mysql-server

docker run -it \
--link mysql-server:mysql \
-v /storage/mysql-server/datadir:/var/lib/mysql \
-v /storage/backups:/backups \
--rm=true \
severalnines/mysql-pxb \
sh -c 'exec /'

# backup of mysql from hosted machine

docker run -it \
-v /var/lib/mysql:/var/lib/mysql \
-v /storage/backups:/backups \
--rm=true \
severalnines/mysql-pxb \
sh -c 'exec innobackupex --host="$hostname" --port="3306" --user=root --password="$rootpassword" /backups'


# cluster control container:
docker run -d --name clustercontrol -p 5000:80 severalnines/clustercontrol


1) official container

Here are 2 commands to start Elasticsearch with Kibana using docker.

# docker run -d -p 9200:9200 -p 9300:9300 -e ES_HEAP_SIZE=10g elasticsearch

Find the name of the container and link it to kibana by changing kibana_name_here below like this...

# docker run -d -p 5601:5601 --link   kibana_name_here:elasticsearch -e ELASTICSEARCH_URL=http://elasticsearch:9200 kibana

Login to the newly created elastic container and install plug-ins
docker exec -it container_id bash

# pwd

# bin/plugin install analysis-phonetic

Once the plugin is installed, restart the container so that elastic service will be restarted....
# docker restart c44004a47f46

2) custom container

elastic - customize elasticsearch installation and maintenance


adminer is the web interface to connect to any database like postgresql, mysql or oracle
Instead of linking adminer on any port, use --net=host to use the default port 80 of host machine. It will also use default mysql port 3306 that is fortunately linked to mysql container as shown above.

If you do not want to add one more parameter i.e. --net then use the default "bridge" network protocol. You will need to use the following command to find the IP address of the docker host.

# ip addr show docker0

This command will show the docker host IP address on the docker0 network interface.


wget -O /tmp/index.php

connect to any database like mysql, pgsql, redshift, oracle or mongoDB

postgresql (redshift) or mysql

docker run -it -p 8060:80 -v /tmp/:/var/www/html/ shantanuo/phpadminer


docker run -d -p 8070:80 -v /tmp:/var/www/html ishiidaichi/apache-php-mongo-phalcon


docker run -d -p 8080:80 -v /tmp/:/app lukaszkinder/apache-php-oci8-pdo_oci

# not sure about how to support mssql


compact packages

1) pyrun
python versions 2 and 3 compact, without any external libraries, for basic testing like this...
here is an easy way to convince people to upgrade to python 3.0+

# docker run -it --rm shantanuo/pyrun:2.7 python
>>> 3/2

# docker run -it --rm shantanuo/pyrun:3.4 python
>>> 3/2

Python 2.7 version returns absolute value 1 while 3.4 version correctly returns 1.5

2) staticpython 
4 MB single file python package!

3) socket 
 python with application files

Complete python package

4) conda official 
Official python installation:

5) miniconda customized
Here is an impage with pandas and sqldf modules

# Start ipython container that is based on miniconda image in a screen session
docker run -p 7778:7778 -t shantanuo/miniconda_ipython_sqldf /bin/bash

# better start with environment variables
docker run -p 7778:7778 \
-t shantanuo/miniconda_ipython_sqldf /bin/bash

# Log-in to newly created container
docker exec -it $(docker ps -l -q) /bin/bash

# Start ipython notebook on port 7778 that can be accessed from anywhere (*)
cd /home/
ipython notebook --ip=* --port=7778

# and use the environment keys in your code like this...
import boto3
import os
s3 = boto3.client('s3',aws_access_key_id=os.environ['DEV_ACCESS_KEY'], aws_secret_access_key=os.environ['DEV_SECRET_KEY'])

application containers

Here is an example from amazon about how to build your own container with php application.

Utility containers

1) myscan 

Use OCR to read any image.
alias pancard='docker run -i --rm -v "$(pwd)":/home/ shantanuo/myscan python / "$@"'


pancard 1crop.jpg

2) panamapapers 

container with sqlite database ready for query

3) newrelic
newrelic docker image that works like nagios

docker run -d \
--privileged=true --name nrsysmond \
--pid=host \
--net=host \
-v /sys:/sys \
-v /dev:/dev \
-v /var/run/docker.sock:/var/run/docker.sock \
-v /var/log:/var/log:rw \
-e NRSYSMOND_license_key=186b2a8d6af29107609abca749296b46cda9fa69 \
-e NRSYSMOND_logfile=/var/log/nrsysmond.log \

docker run -d \
  -e NEW_RELIC_LICENSE_KEY=186b2a8d6af29107609abca749296b46cda9fa69  \
  -e AGENT_HOST= \
  -e AGENT_USER=root \

4) OCS inventory
docker run -d -p 80:80 -p 3301:3306 zanhsieh/docker-ocs-inventory-ng
(username:admin, password:admin)

5) selenium
simulate a browser (crome) with selenium pre-installed

docker run -d -v /dev/shm:/dev/shm -p 4444:4444 selenium/standalone-chrome

The Hub url...

6) Deploying registry server
#Start your registry:
docker run -d -p 5000:5000 --restart=always --name registry registry:2

#You can now use it with docker. Tag any image to point to your registry:
docker tag image_name localhost:5000/image_name

#then push it to your registry:
docker push localhost:5000/image_name

# pull it back from your registry:
docker pull localhost:5000/image_name

# push the registry container to hub
docker stop registry
docker commit registry
docker push registry

7) Docker User Interface
docker run -d -p 9000:9000 -v /var/run/docker.sock:/docker.sock --name dockerui abh1nav/dockerui:latest -e="/docker.sock"

8) docker clean up container
docker run -v /var/run/docker.sock:/var/run/docker.sock -v /var/lib/docker:/var/lib/docker --rm martin/docker-cleanup-volumes --dry-run

9) prometheus monitoring
check port 9090 and cadvisor on 8080

git clone
cd prometheus/

/usr/local/bin/docker-compose  up -d

10) open refine utility
# docker run --privileged -v /openrefine_projects/:/mnt/refine -p 35181:3333 -d psychemedia/ou-tm351-openrefine
Or use this:
docker run -p 3334:3333 -v /mnt/refine -d psychemedia/docker-openrefine

11) Freeswitch
docker run -d sous/freeswitch

12) mongodb
from tutum
docker run -d -p 27017:27017 -p 28017:28017 -e MONGODB_PASS="mypass" tutum/mongodb

offical image with wiredTiger engine
docker run -p 27017:27017 -v /tokudata:/data/db -d mongo --storageEngine wiredTiger

with tokumx compression engine
docker run -p 27017:27017 -v /tokudata:/data/db -d ankurcha/tokumx

13) Consul Monitor
docker run -d --name=consul --net=host gliderlabs/consul-server -bootstrap -advertise=

14) Registrator container
$ docker run -d \
--name=registrator \
--net=host \
--volume=/var/run/docker.sock:/tmp/docker.sock \
gliderlabs/registrator:latest \

15) wordpress
docker has official wordpress containers

16) Packetbeat container
docker run -d --restart=always --net=host shantanuo/packetbeat-agent

17) Django

docker run --name some-django-app -v "$PWD":/usr/src/app -w /usr/src/app -p 8000:8000  -e location=mumbai -d django bash -c "pip install -r requirements.txt && python runserver"

18) rabbitmq
docker run -d --hostname oksoft -p 8080:15672 rabbitmq:3-management

19) ruby and passenger
(official docker image from phusion)

docker run -d -p 3000:3000 phusion/passenger-full

# login to your container:
docker exec -it container_id bash

# change to opt directory
cd /opt/
mkdir public

# a test file
curl > public/index.html

# start passenger:
passenger start

Labels: , ,


Backup mysql using a container!

Suppose you have a MySQL container running named "mysql-server", started with this command:

$ docker run -d \
--name=mysql-server \
-v /storage/mysql-server/datadir:/var/lib/mysql \
-e MySQL_ROOT_PASSWORD=mypassword \

Then, to perform backup against the above container, the command would be:

$ docker run -it \
--link mysql-server:mysql \
-v /storage/mysql-server/datadir:/var/lib/mysql \
-v /storage/backups:/backups \
--rm=true \
severalnines/mysql-pxb \
sh -c 'exec /'

Labels: , ,


June 2001   July 2001   January 2003   May 2003   September 2003   October 2003   December 2003   January 2004   February 2004   March 2004   April 2004   May 2004   June 2004   July 2004   August 2004   September 2004   October 2004   November 2004   December 2004   January 2005   February 2005   March 2005   April 2005   May 2005   June 2005   July 2005   August 2005   September 2005   October 2005   November 2005   December 2005   January 2006   February 2006   March 2006   April 2006   May 2006   June 2006   July 2006   August 2006   September 2006   October 2006   November 2006   December 2006   January 2007   February 2007   March 2007   April 2007   June 2007   July 2007   August 2007   September 2007   October 2007   November 2007   December 2007   January 2008   February 2008   March 2008   April 2008   July 2008   August 2008   September 2008   October 2008   November 2008   December 2008   January 2009   February 2009   March 2009   April 2009   May 2009   June 2009   July 2009   August 2009   September 2009   October 2009   November 2009   December 2009   January 2010   February 2010   March 2010   April 2010   May 2010   June 2010   July 2010   August 2010   September 2010   October 2010   November 2010   December 2010   January 2011   February 2011   March 2011   April 2011   May 2011   June 2011   July 2011   August 2011   September 2011   October 2011   November 2011   December 2011   January 2012   February 2012   March 2012   April 2012   May 2012   June 2012   July 2012   August 2012   October 2012   November 2012   December 2012   January 2013   February 2013   March 2013   April 2013   May 2013   June 2013   July 2013   September 2013   October 2013   January 2014   March 2014   April 2014   May 2014   July 2014   August 2014   September 2014   October 2014   November 2014   December 2014   January 2015   February 2015   March 2015   April 2015   May 2015   June 2015   July 2015   August 2015   September 2015   January 2016   February 2016   March 2016   April 2016   May 2016   June 2016   July 2016  

This page is powered by Blogger. Isn't yours?