How to use the MongoDB & NodeJS with Docker
Chen Zhao Lin teacher [email protected] https://www.facebook.com/groups/247788228752702/(2015/5/25)
https://chenlinslim.wordpress.com/
Participation in the text:
http://ifdattic.com/how-to-mongodb-nodejs-docker/
Https://github.com/pertrai1/365-programming/tree/master/mongo/Week3/homework_3_3_mongoproc_version/hw3-2and3-3 /hw3-2and3-3/blog (Textbook Code)
Http://proserge.kh.ua/coding/index.php/post/33/MongoDB+for+NodeJs+devs+week4%3A+Perfomance (Textbook solution)
stating:
node. js + MONGO DB is a tool used to build [Web + database] project, and the above textbook is a simple blog in the environment of Docker. The textbook code part of the open space, mainly for the reader to complete their own, the answer is also web site, for the convenience of display I combine 2 as a project [Hw3-2and3-3.zip], Project Environment Win7.
Operation Step (Docker installation and environment setting)
https://docs.docker.com/machine/(Win7 installed Docker machine)
mkdir C:\docker-software
$ curl-l https://github.com/docker/machine/releases/download/v0.2.0/docker-machine_windows-amd64.exe > mkdir c \ Docker-software\docker-machine.exe (installed Docker machine)
$ curl-l https://get.docker.com/builds/Windows/x86_64/docker-latest.exe > C:\docker-software\docker.exe (Installation Docker CLI)
Console/= System = Advanced system settings = Environment variables
Path=c:\docker-software, ........ ..................
$ docker-machine ls
NAME ACTIVE DRIVER State URL
Https://www.virtualbox.org/wiki/Downloads (Installed VirtualBox)
//--------------------------------------------------------------------------------------------
$docker-machine Create--driver VirtualBox dev (vitualbox Dev)
Please do not open dev at VirtualBox
C:\windows\system32>docker-machine ls
NAME ACTIVE DRIVER State URL SWARM
Dev * VirtualBox Running tcp://192.168.99.100:2376
How to share information with the dev host and container; container and window
Please refer to Https://github.com/rocker-org/rocker/wiki/Sharing-files-with-host-machine
The following directives make Dev:/c/users/slim/foobar, container:/home/rstudio/foobar information synchronized
$docker run-d-P 8787:8787-v/c/users/slim/foobar:/home/rstudio/foobar Rocker/rstudio
Dev:/c/users/slim/foobar Information Folder
Container:/home/rstudio/foobar folder
Rocker/rstudio:images
Show results
$docker Images
REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE
Rocker/rstudio latest cdf09599493c 9 days ago 808.6 MB
$docker PS
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
9e937efff19e rocker/rstudio:latest "/usr/bin/supervisor minutes ago up minutes 0.0.0.0:8787->8787/tcp Insane_ Bell
$docker-machine IP
192.168.99.100
Browser input: http://192.168.99.100:8787/
Login User/password:rstudio/rstusio
Through the lower right corner upload the window file into container:/home/rstudio/foobar
Select file through the lower right corner more->export the Container/home/rstudio/foobar file to window
$docker-machine SSH Dev
[Email protected]:~ $ls/c/users/slim/foobar
You'll see Rocker/rstudio container:/home/rstudio/foobar's content
Rocker/rstudio container can be seen as a medium-pass tool, and other container can captured access to Windows.
(dev) $ifconfig |less//inspection site Dev 192.168.99.100
(Dev) $passwd Docker
changing password for Docker
#Old password:xxxx
#New password:xxxx
The good things about using putty are operational aspects
Download Putty.exe, set ip=192.168.99.100
Login:docker
Password:xxxxxxx
(Dev) $mkdir/tmp/share
(Dev) $id Docker
uid=1000 (Docker) gid=50 (staff) groups=50 (Docker)
(Dev) $mkdir/home/docker/work_directory
(Dev) $cd/home/docker/work_directory
(Dev) $ $docker pull mongo:2.6
(Dev) $ $docker images
REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE
MONGO 2.6 28c8b6d98aa7 hours ago 392.4 MB
(Dev) $docker run-v "$ (PWD)":/data--name mongo-d mongo:2.6 mongod--smallfiles
-V "$ (pwd)":/data: Download Dev's current path under Container/data
--name Mongo:container named MONGO
Mongo:image Name
Mongod--smallfiles: Execute command MONGO; --smallfiles:sets MongoDB to use a
Smaller default file size
(Dev) $docker ps-a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
616BC65FB5AD mongo:2.6 "/entrypoint.sh mong seconds ago up one seconds 27017/tcp MONGO
(dev) $docker exec-it MONGO Bash
$ MONGO
>use Test (build repository test)
> Db.col.insert ({"A": 4})
Writeresult ({"ninserted": 1})
> Db.col.find (). Pretty ()
{"_id": ObjectId ("555d2b0e30798a76ebb19bf7"), "a": 4}
> Show DBS
Admin (empty)
Local 0.031GB
Test 0.031GB
>exit
$exit
$docker ps-a
06876ff7384e mongo:2.6 "/entrypoint.sh mong hours ago up minutes 27017/tcp MONGO
The following instruction functions directly into the MONGO hint: (This time container has been connected container)
(Dev) $docker run-it--rm=true--link mongo:mongo mongo:2.6 sh-c ' exec Mongo ' $MONGO _port_27017_tcp_addr: $MONGO _port_270 17_tcp_port/test "'
-it: Cross-talk and execute bash
--link MONGO:MONGO:ADD link to another container:
--rm mongo:automatically Remove the container when it exits
Sh-c ' EXEC MONGO
The following tests link the test repository for success
>show DBS
> Show DBS
Admin (empty)
Local 0.031GB
Test 0.031GB
> DB
Test
> Db.col.find (). Pretty ()
{"_id": ObjectId ("555d446834ee62be367979ce"), "a": 4}
(Use Puuty to open a terminal connection to dev: observing container)
(Dev) $docker ps-a
311be231a055 mongo:2.6 "\"/entrypoint.sh sh seconds ago up seconds 27017/tcp
06876ff7384e mongo:2.6 "/entrypoint.sh mong hours ago up minutes 27017/tcp
Back to the original terminal machine
>exit (jump out of database and container)
Docker ps-a//Container (311be231a055) has been removed
06876ff7384e mongo:latest "/entrypoint.sh mong hours ago up minutes 27017/tcp
Another way to connect container (06876ff7384e)
(dev) $docker exec-it MONGO bash//login container 06876ff7384e
The following tests link the test repository for success
$mongo
> Show DBS
Admin (empty)
Local 0.031GB
Test 0.031GB
> DB
Test
> Db.col.find (). Pretty ()
{"_id": ObjectId ("555d446834ee62be367979ce"), "a": 4}
//-----------------------------------------------
How to Container:mongo the repository to dev:
(dev) $docker exec-it MONGO Bash (Bash connect container 06876ff7384e)
The/data/test-backup of the Database:test information repository
(container) $mongodump--db test--out/data/test-backup
Connected to:127.0.0.1
2015-05-07t04:59:29.474+0000 database:test To/data/test-backup/test
2015-05-07t04:59:29.474+0000 test.system.indexes To/data/test-backup/test/system.indexes.bson
2015-05-07t04:59:29.475+0000 1 Documents
2015-05-07t04:59:29.475+0000 Test.col To/data/test-backup/test/col.bson
2015-05-07t04:59:29.476+0000 1 Documents
2015-05-07t04:59:29.476+0000 Metadata for Test.col To/data/test-backup/test/col.metadata.json
Dev shows the contents of the repository
(Dev) $ls/home/docker/work_directory/test-backup/test/
Col.bson Col.metadata.json System.indexes.bson
How to get the repository from container to window
Using the Rocker/rstudio container tool:
/data/test-backup/test the repository that has been sent out to dev to window
(Dev) $cp-R/home/docker/work_directory/test-backup//c/users/slim/foobar
Enter http://http://192.168.99.100:8787/, the lower right corner of the Test-backup folder, select more->export; The system will pack it. zip out window
The MONGO Library is container by window (please refer to the Front for container
Window Mutual Information
Below are the steps for Dev-container):
return dev database to container database:test-restored
(dev) $docker exec-it MONGO Bash
Archive/data/test-backup/test file back to new repository test-restored)
(container) $mongorestore--db test-restored/data/test-backup/test
Connected to:127.0.0.1
2015-05-07t05:11:04.258+0000/data/test-backup/test/col.bson
2015-05-07t05:11:04.258+0000 going into namespace [Test-restored.col] 1 objects found
2015-05-07t05:11:04.259+0000 Creating index: {key: {_id:1}, Name: "_id_", ns: "Test-restored.col"}
(container) $mongo
>use test-restored
>db.col.find (). Pretty ()//Experience database:test-restored contents
{"_id": ObjectId ("553f095dabab2eeb97f5ae14"), "a": 4}
>exit (Leave MONGO)
$exit (end bundle container)
//-------------------------------------------------------
node. JS Installation
//-------------------------------------------------------
(dev) $docker pull node:latest
(Dev) $docker images
REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE
MONGO 2.6 28c8b6d98aa7 hours ago 392.4 MB
Node latest 86a1fcd53530 3 days ago 711.1 MB
(Dev) $docker run-it--rm node//execute container and enter the talk mode and remove container
>console.log (' It works!! ')
Show It Works
Ctl^c (2 times) jump, end container
Compress additional files hw3-2and3-3.zip to c:\home\share\hw3-2and3-3
Browser input into http://192.168.99.100:8787
Select Upload to hw3-2and3-3.zip into container rocker/rstudio:/home/rstudio/foobar
(Dev) $ ls/c/users/slim/foobar
hw3-2and3-3/
(Dev) $cd/c/users/slim/foobar/hw3-2and3-3/
(Dev) $docker run-it--name node-v "$ (PWD)":/data--link mongo:mongo-w/data-p 8082:8082--rm node bash
Download MONGO container
-w/data:working directory inside the container (log container directly into/data
-P 8082:8082:publish all exposed ports to random ports
Node:images Name
Bash:bash Login
(container) [Email PROTECTED]:/DATA$CD Blog
NPM Install (NPM installed)
Node App.js (activation server side)
Express server listening on port 8082
Browser input http://192.168.99.100:8082//Easy Blog Management and log-in
Maybe the wrong mistake.
Mongoerror:driver is incompatible with the This server version
Question Answer: https://github.com/sharelatex/sharelatex/issues/296
Build a Web server (for Win7) with MongoDB & NodeJS in the Docker environment