MongoDB Docker and Raspberry Pi

MongoDBDockerandRaspberryPi

1SetupMongoDBinDocker

SimpleMakefile

IMAGE=sillycat/public

TAG=raspberrypi-mongodb

NAME=raspberrypi-mongodb

docker-context:

build:docker-context

dockerbuild-t$(IMAGE):$(TAG).

run-init:

dockerrun-d-p27017:27017-p28017:28017-v/mnt/driver1/data/mongodb:/var/lib/mongodb-v/opt/mongodb/log:/var/log/mongodb-eRUNNING_MODULE=INIT--name$(NAME)$(IMAGE):$(TAG)

run:

dockerrun-d-p27017:27017-p28017:28017-v/mnt/driver1/data/mongodb:/var/lib/mongodb-v/opt/mongodb/log:/var/log/mongodb-eRUNNING_MODULE=RUN--name$(NAME)$(IMAGE):$(TAG)

debug:

dockerrun-ti-p27017:27017-p28017:28017-v/mnt/driver1/data/mongodb:/var/lib/mongodb-v/opt/mongodb/log:/var/log/mongodb--name$(NAME)$(IMAGE):$(TAG)/bin/bash

clean:

dockerstop${NAME}

dockerrm${NAME}

logs:

dockerlogs${NAME}

publish:

dockerpush${IMAGE}:${TAG}

fetch:

dockerpull${IMAGE}:${TAG}

Dockerfileisalsosimple,becauseitisanapt-getinstall

#SetupFTPinDocker

#PrepretheOS

FROMresin/rpi-raspbian:jessie

MAINTAINERCarlLuo<[email protected]>

ENVDEBIAN_FRONTENDnoninteractive

ENVDAEMONUSERroot

RUNecho"debhttp://mirrordirector.raspbian.org/raspbian/jessiemaincontribnon-freerpi\n\

deb-srchttp://archive.raspbian.org/raspbian/jessiemaincontribnon-freerpi\n\

">/etc/apt/sources.list

RUNapt-get-yupdate

RUNapt-get-ydist-upgrade

#installmongodsoft

RUNapt-get-yinstallmongodb-server

#configuretheserver

ADDconf/mongodb.conf/etc/

ADDconf/mongodb_auth.conf/etc/mongodb_auth.conf

ADDconf/mongodb_noauth.conf/etc/mongodb_noauth.conf

#starttheapplication

EXPOSE2701728017

RUNmkdir-p/app/

ADDstart.sh/app/

WORKDIR/app/

CMD["./start.sh"]

Fortheconfigurationmongoldb.conf,Ionlychangetheauthandbind_ip

bind_ip=0.0.0.0

port=27017

Theflowwillbesystemstartmongo,addadminuser,enableauthandrestartthemongoDB

start.shisasfollow:

#!/bin/sh-ex

if["$RUNNING_MODULE"="INIT"];then

#startnonauthserver

/etc/init.d/mongodbstart

#sleep2minutes

sleep2m

#adduser

mongoadmin--eval"db.addUser('supper',‘password')"

#setauthandrestart

cp/etc/mongodb_auth.conf/etc/mongodb.conf

/etc/init.d/mongodbrestart

else

#setauth

cp/etc/mongodb_auth.conf/etc/mongodb.conf

#startserver

/etc/init.d/mongodbstart

fi

#Runmongoastherunningprocess,thisisrequiredtokeepthedockerprocessrunning

tail-f/dev/null

CheckmongoDBAUTH

>showdbs

admin0.0625GB

local0.03125GB

mydb0.0625GB

test0.0625GB

2SwitchtouseadminDB

>useadmin

switchedtodbadmin

checkifthereisanyusersinDB

>db.system.users.find();

adduserinadmin

>db.addUser("super","password")

Verifyauth

>db.auth("super","password")

1

Logintotheauthuserwithcommand

>mongo--hostsillycat.ddns.net--port27017-usuper-ppassword--authenticationDatabaseadmin

Itmayrequiredusernameandpasswordwithparams

-uusername-ppassword

Connecttomyserver

>mongo--hostsillycat.ddns.net--port27017

Choosedatabase

>usemydb;

New/Save/Querydata

>j={name:"mongo"};

>db.things.save(j);

>db.things.find();

dumpcommandallthedatabase

>mongodump-hsillycat.ddns.net-o~/data/mongodb/

restoreallthedatabase

>mongorestore-hsillycat.ddns.net~/data/mongodb/--drop

References:

mongoDB

http://yannickloriot.com/2016/04/install-mongodb-and-node-js-on-a-raspberry-pi/

http://blog.51yip.com/nosql/1573.html

http://www.runoob.com/mongodb/mongodb-mongodump-mongorerstore.html

redis

http://andreas-kongelstad.tumblr.com/post/51622770030/part-2-installing-redis-on-raspberry-pi

mongoDBAUTH

http://bubkoo.com/2014/02/07/mongodb-authentication/

http://stackoverflow.com/questions/10743905/how-can-i-use-a-script-to-create-users-in-mongodb

http://stackoverflow.com/questions/22682891/create-a-mongodb-user-from-commandline

相关推荐