- follow mongo instructions to install locally.
- run
mongod
-
Docker docker implementation will require access to host ports, to do this you will be required to add host network
--network host
**Full Example** ```shell docker run -d \ --name cezerin2 \ -p 3001:80 \ -v /content-on-host:/var/www/cezerin2/public/content \ --network host \ cezerin2/cezerin2:latest ```
-
pm2 Deloy normally with pm2. here
pm2 start app.js
```shell
docker run -d \
--name store-db \
-v /storage-location-on-host:/data/db \
mongo:latest
```
-
Docker You are required to link to the database image and set it to the DB_HOST.
--link store-db:db \ -e DB_HOST=db \
Full Example
docker run -d \ --name cezerin2 \ --link store-db:db \ -p 3001:80 \ -e DB_HOST=db \ -v /content-on-host:/var/www/cezerin2/public/content \ cezerin2/cezerin2:latest
-
pm2 You will be required to expose the port in the docker command.
-p 27017:27017
Then you can Deloy normally with pm2. here
pm2 start app.js
-
I'll use Mongo Altas to deploy database.
-
Click Build Cluster
- Choose an provider:
AWS
- Choose a region:
N. Virginia (us-east-1)
- Choose a tier region:
M0
(Sandbox Free) - Choose a cluster name:
Cezerin-db
- Choose an provider:
-
Create User
- Click Customer Security
- Click Add New User Role
- Choose Username:
cezerin
- Choose Password:
cezerin
- Choose User Privileges:
Atlas Admin
-
Add WhiteList IP
- Click IP Whitelist
- Click Add IP ADDRESS
- Click Add current IP Address
-
Click Connect
- Select:
Connect Your Application
- Select Driver:
nodejs
- Select Version:
3.0 or later
- Copy connection string:
mongodb+srv://cezerin:<password>@cezerin-db-0ga32.mongodb.net/test?retryWrites=true
- Select:
-
Update string url
- change
<password>
to provided password - remove
?retryWrites=true
(doesn't support ?) - change
test
to database nameshop
- should be like
mongodb+srv://cezerin:[email protected]/shop
- change
-
-
Docker You are required to referernce the database url in the docker configuration
-e DB_URL=mongodb+srv://cezerin:[email protected]/shop
Full Example
docker run -d \ --name cezerin2 \ --link store-db:db \ -p 3001:80 \ -e DB_URL=mongodb+srv://cezerin:[email protected]/shop \ -v /content-on-host:/var/www/cezerin2/public/content \ cezerin2/cezerin2:latest
-
pm2
DB_URL=mongodb+srv://cezerin:[email protected]/shop \ pm2 start process.json