dubdiff/docker/start-mongodb

38 lines
966 B
Plaintext
Raw Normal View History

#! /bin/bash
# Start a data container and a mongodb instance
echo
# test if the data-db container has been created
if docker inspect -f {{.Name}} data-db
then
echo "* data-db exists"
else
echo "* creating data-db"
# The data container has a volume at /data/db, is named 'data' and is based on mongo
docker create -v /data/db --name data-db mongo echo "Data container - database"
fi
echo
# test if the mongo db server has been created
if docker inspect -f {{.Name}} mongodb
then
# make sure the server is running
if docker inspect -f {{.State.Running}} mongodb
then
echo "* mongodb exists and is running"
else
echo "* starting mongodb"
docker start mongodb
fi
else
echo "* creating new mongodb server"
# Start a mongo db server as a daemon
# The server will use the data-db container as a volume
docker run -p 27017 --name=mongodb --volumes-from=data-db -d mongo
fi