Friday, July 24, 2015

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

No comments: