Friday, July 24, 2015

Docker Redis

1) Create a script as such:
CONTAINER_NAME="redis_server"
REDIS_DATA_DIR="`pwd`/data-dir/redis/"
HOST_PORT_1="6379"

if [ ! -d "${REDIS_DATA_DIR}" ]
then
    mkdir -p "${REDIS_DATA_DIR}"
fi

docker rm ${CONTAINER_NAME}
docker run --name ${CONTAINER_NAME} --rm \
   -p ${HOST_PORT_1}:6379 \
   -v ${REDIS_DATA_DIR}:/data \
    redis

Postgres Query: Given an index find associated table

select
    t.relname as table_name,
    i.relname as index_name,
    array_to_string(array_agg(a.attname), ', ') as column_names
from
    pg_class t,
    pg_class i,
    pg_index ix,
    pg_attribute a
where
    t.oid = ix.indrelid
    and i.oid = ix.indexrelid
    and a.attrelid = t.oid
    and a.attnum = ANY(ix.indkey)
    and t.relkind = 'r'
    and i.relname = 'Index_to_search_for'
group by
    t.relname,
    i.relname
order by
    t.relname,
    i.relname;
 
 
Source:
http://stackoverflow.com/questions/2204058/list-columns-with-indexes-in-postgresql

Docker MongoDB

1) Create a directory for local data:

mkdir `pwd`/data-dir

2) Create a script as such:

CONTAINER_NAME="mongodb_server"
MONGO_DATA_DIR="`pwd`/data-dir"
HOST_PORT_1="27017"

if [ ! -d "${MONGO_DATA_DIR}" ]
then
    mkdir -p "${MONGO_DATA_DIR}"
fi

docker rm ${CONTAINER_NAME}
docker run --name ${CONTAINER_NAME} --rm \
   -p ${HOST_PORT_1}:27017 \
   -v ${MONGO_DATA_DIR}:/data/db \
   mongo