docker部署nodejs、mongodb
15973 ワード
node
docker run --rm -itd -p 3000:3000 --name node_api -v "$(pwd)":/webapp/nodejs/node_api -w /webapp/nodejs/node_api node npm start
/webapp/nodejs/node_api
docker run -d -p 27017:27017 -v "$(pwd)"/opt/mongodb/affiliate:/webapp/nodejs/node_api_db--name mongo
docker run -p 27017:27017 -v opt/mongodb/affiliate:/webapp/nodejs/node_api_db -d mongo
docker run -p 27017:27017 -v $PWD/opt/mongodb/affiliate:/webapp/nodejs/node_api_db -d mongo
docker run -p 27017:27017 -v $PWD:/webapp/nodejs/node_api_db --name mongo -d mongo --dbpath /opt/mongodb/affiliate
mongo , /data/db
管理mongodbdocker ps-aはすべての容器docker psを調べて運行中の容器を調べます.
root@ubuntu:/# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
2d3cd251be6b node "npm start" 15 minutes ago Up 15 minutes 0.0.0.0:3000->3000/tcp node_api
bf0cda8a8e0a mongo "docker-entrypoint..." 2 hours ago Up 2 hours 0.0.0.0:27017->27017/tcp hungry_wright
起動済みの容器に入るroot@ubuntu:/# docker exec -it hungry_wright bash
root@bf0cda8a8e0a:/# ps -ef | grep mongo
mongodb 1 0 0 07:47 ? 00:00:32 mongod
root 335 328 0 09:28 pts/0 00:00:00 grep mongo
root@bf0cda8a8e0a:/# ps -ef | grep node
root 337 328 0 09:28 pts/0 00:00:00 grep node
root@bf0cda8a8e0a:/# mongo
MongoDB shell version v3.4.10
connecting to: mongodb://127.0.0.1:27017
MongoDB server version: 3.4.10
Server has startup warnings:
2017-11-14T07:47:37.188+0000 I STORAGE [initandlisten]
2017-11-14T07:47:37.188+0000 I STORAGE [initandlisten] ** WARNING: Using the XFS filesystem is strongly recommended with the WiredTiger storage engine
2017-11-14T07:47:37.188+0000 I STORAGE [initandlisten] ** See http://dochub.mongodb.org/core/prodnotes-filesystem
2017-11-14T07:47:37.447+0000 I CONTROL [initandlisten]
2017-11-14T07:47:37.447+0000 I CONTROL [initandlisten] ** WARNING: Access control is not enabled for the database.
2017-11-14T07:47:37.447+0000 I CONTROL [initandlisten] ** Read and write access to data and configuration is unrestricted.
2017-11-14T07:47:37.447+0000 I CONTROL [initandlisten]
2017-11-14T07:47:37.447+0000 I CONTROL [initandlisten]
2017-11-14T07:47:37.447+0000 I CONTROL [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/enabled is 'always'.
2017-11-14T07:47:37.447+0000 I CONTROL [initandlisten] ** We suggest setting it to 'never'
2017-11-14T07:47:37.447+0000 I CONTROL [initandlisten]
> show dbs
admin 0.000GB
affiliate 0.011GB
local 0.000GB
> use affiliate
switched to db affiliate
> show collections
affiliate
dy2018
dytt8
sessions
tradedoubler
users
>
mongodb shell
,mongodb
root@bf0cda8a8e0a:/# ls
bin data docker-entrypoint-initdb.d etc lib media opt root sbin sys usr webapp
boot dev entrypoint.sh home lib64 mnt proc run srv tmp var
root@bf0cda8a8e0a:/# cd data/
root@bf0cda8a8e0a:/data# ls
configdb db
root@bf0cda8a8e0a:/data# cd db
root@bf0cda8a8e0a:/data/db# ls
WiredTiger collection-17--7989148561081090875.wt index-18--7989148561081090875.wt
WiredTiger.lock collection-2--7989148561081090875.wt index-3--7989148561081090875.wt
WiredTiger.turtle collection-5--7989148561081090875.wt index-4--7989148561081090875.wt
WiredTiger.wt collection-8--7989148561081090875.wt index-6--7989148561081090875.wt
WiredTigerLAS.wt diagnostic.data index-7--7989148561081090875.wt
_mdb_catalog.wt index-1--7989148561081090875.wt index-9--7989148561081090875.wt
collection-0--7989148561081090875.wt index-11--7989148561081090875.wt journal
collection-10--7989148561081090875.wt index-12--7989148561081090875.wt mongod.lock
collection-13--7989148561081090875.wt index-14--7989148561081090875.wt sizeStorer.wt
collection-15--7989148561081090875.wt index-16--7989148561081090875.wt storage.bson
root@bf0cda8a8e0a:/data/db#
# , /data
nodeプロジェクトを表示root@ubuntu:/# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
2d3cd251be6b node "npm start" 23 minutes ago Up 23 minutes 0.0.0.0:3000->3000/tcp node_api
bf0cda8a8e0a mongo "docker-entrypoint..." 2 hours ago Up 2 hours 0.0.0.0:27017->27017/tcp hungry_wright
root@ubuntu:/# docker exec -it node_api bash
root@2d3cd251be6b:/webapp/nodejs/node_api# ls
api common log4js-master.json models opt public test
app.js controls log4js-worker.json node_api.iml package-lock.json routes views
bin log.js logs node_modules package.json settings.js
root@2d3cd251be6b:/webapp/nodejs/node_api# cd /
root@2d3cd251be6b:/# ls
bin boot dev etc home lib lib64 media mnt opt proc root run sbin srv sys tmp usr var webapp
root@2d3cd251be6b:/# cd webapp/
root@2d3cd251be6b:/webapp# ls
nodejs
root@2d3cd251be6b:/webapp# cd nodejs/
root@2d3cd251be6b:/webapp/nodejs# ls
node_api
root@2d3cd251be6b:/webapp/nodejs# cd node_api/
root@2d3cd251be6b:/webapp/nodejs/node_api# ls
api bin controls log4js-master.json logs node_api.iml opt package.json routes test
app.js common log.js log4js-worker.json models node_modules package-lock.json public settings.js views
root@2d3cd251be6b:/webapp/nodejs/node_api#
参照http://blog.shiqichan.com/Dockerizing-a-Node-js-Web-Application/#more DockerでNode.jsのWebアプリケーションを実行します.http://www.jb51.net/article/116783.htm dockerでは、mongodbデータベースを使用しています.