Use docker mongo server and client
// start server and run in background:
$ docker run --name mongoserver -d mongo:3.2
// start client, quit with Ctrl-d, the container will be removed when quit:
$ docker run -it --link mongoserver:mongo --rm mongo:3.2 sh -c 'exec mongo "$MONGO_PORT_27017_TCP_ADDR:$MONGO_PORT_27017_TCP_PORT/test"'
// stop server:
$ docker stop mongoserver
// start server again:
$ docker start mongoserver
// stop and remove server and all the data
$ docker stop mongoserver
$ docker rm -vf mongoserver
// start a new server and run in background:
$ docker run --name mongoserver -d mongo:3.2
$ docker run --link mongoserver:mongo --rm mongo:3.2 sh -c 'exec echo "$MONGO_PORT_27017_TCP_ADDR"'
172.17.0.4
Ref: https://hub.docker.com/_/mongo/
Use native mongo client
Install mongodb client: sudo aptitude install mongodb-org-shell
;
Install mongodb server and connect to it:
sudo usermod -aG docker leo
docker run --name mongo3 -p 27017:27017 -d daocloud.io/mongo
mongo
> db.version()
> exit
Stop and restart mongodb server:
docker stop mongo3
docker start mongo3
Remove mongodb completely:
docker ps -a
docker stop mongo3
docker rm mongo3
docker images
docker rmi daocloud.io/mongo
Note:
You can also pull mongodb image from docker hub with
docker run --name mongo3 -d mongo
, but it's very slow.