I'm trying to use docker for my project these days, but I'm confused with some problem with it.
My project created by nodejs + mongodb + nginx, now I want to publish my project using docker. I don't know whether I should use a node image + a mongodb image + a nginx image and then link them together or I should use a basic image like centos and install node,mongo,nginx then run my server.
And another question, If I try the second way, in my dockerfile I run node server, it need to connect the mongodb use a correct user, but the mongodb doesn't have user authorization config yet when node server runs, so the node server can't run, so how to create a user in Docker file?
Related
Now I have two Linux PC,mongodb is in the first PC which IP is 192.168.1.33,and a
java application on another Linux connect to the mongodb on 192.168.1.33
What I want to do is,prepare everything and make both Linux systems into docker images,and when I am in productive environment,I can simply restore the images that I prepared,and everything is OK,so I do not need complex deployment steps.
but the problem is,the IP of mongodb will change,and the IP 192.168.1.33 is written in my configuration file of my java application,it will not change automatically,is there a automated way?
Basics
We create Docker-file with minimal installation steps.
We create docker-Image from that Docker-file in step-1.
We create container from the step-2 image and expose the important port as required.
For your problem.
creating-a-docker-image-with-mongodb This article will help to dockerize the mongodb.
but the problem is,the IP of mongodb will change,and the IP
192.168.1.33 is written in my configuration file of my java application,it
will not change automatically,is there a automated way?
If you expose the mongo-db port to docker host you can use same
docker-host-IP:<exposed-port>
Ref from the article sudo docker run -p 27017:27017 -i -t my_new_mongodb
Example: 192.168.1.33 is your docker-host where mongodb container is running with exposed port 27017. You can add 192.168.1.33:27017 to your JAVA app.
What I want to do is,prepare everything and make both Linux systems
into docker images
You can not convert your VM to direct docker images. Instead you can follow the steps written in Basics and dockerize the both DB and application layer.
2.dockerize-your-java-application refer this link and dockerize you application based on requirements.
Step 1 & 2 will help you to build docker images which you can deploy to multiple servers.
I'm new to Node.Js and all of its "accessories", and I've been trying to set up a Mongodb database, but there are so many ways to do it, it seems, that I've been quite stuck because I'm not sure what goes where and when, anyway, I have a snapshot of the code and the prompt, everything else on the code works.
Also I want to use the mongo cloud database while hosting my node.js on heroku (I got the heroku deployment running), so would I be able to test my database both when doing "node app.js" on my local machine and when I deploy it on heroku?
Additional information:
I NPM'ed mongojs and mongodb
I'm using some sort of cluster on mongodb.atlas (I'm clueless on this)
I set up the mongodb shown on the snapshot above using the option: Clusters > Connect > Connect your application > Short SRV connection string
I had a similar situation with MongoDB working on Heroku but not locally, getting that same error message. Here's the steps I took.
Make sure the database path is configured correctly - it is /data/db by default. I had to run mkdir -p /data/db; you can also choose to manually set that path.
Make sure that MongoDB is running locally before you start your server. You may have to run mongod in the command line to start it; alternately, for Node.js, you can go to package.json and edit your launch configuration by adding "pre-start: 'mongod'" to "scripts," which automatically starts MongoDB when you start your server.
I'm pretty new to DevOps and I'm trying to set up my Node.js app on a AWS server instance. Steps I've taken:
Set up Elastic IP
Launched EC2 instance with Ubuntu server
Connected IP to instance
Allowed incoming connections on port 3000
SSH'd into the server with a .pem file
Now I'm at the point where I need to get my files uploaded to the server. I've used FileZilla (and like it) in the past to upload files but the initial part was already set up. When I set up the site on FileZilla there is no /var/www folder on the remote site.
Don't know how to connect these dots.
Also not sure what I need to run once I successfully upload the files. I imagine npm install when I'm ssh'd into the server? Most of the tutorials out there only go through the basic instance setup.
Thanks!
You don't need to have /var/www. Also, it's better that you use a version control and a remote repository like Github and then SSH to your EC2 and then clone your repository there.
Then cd into your repo and run npm install and then start your app.
And check.
Once you connect to the EC2 instance then clone your code in there. It not mandatory to be in /var/www/html but, it's best practice to keep it there. Once you clone npm install into your project home directory so all the required packages get installed. Then for running your node application in production you have to run it on service as pm2, supervisor, forever, passenger, etc. You can use any of these services and configured appropriately to run your application on desired port. As with pm2, you can follow this guide, install pm2 Then you can run with the following command w.r.t. your environment, like I want to run my application on port 5555 for production
$ PORT=5555 pm2 start app.js --name API --env production -f
Check the status using pm2 list Now, your application is running on http://server-ip:5555/ But, you won't be typing port number every-time. So, you need to configure the web server in front of your application like apache or nginx which will forward all request to your application running port. You could find the best guide to their home page. Then your application is available at http://server-ip/ You can follow this for single configuration of multiple node apps
Hope this helps.
I have a mobile (Ionic 2) chat application with the following implementation, that uses nodejs-0.10 and MongoDB 3.2.7 and Meteor 1.4.1.1. It works perfectly on my localhost.
Now I need to deploy it to an OpenShift server. I have followed the following steps and created a server on OpenShift with Meteor. It is connecting with Git, and I can push my code to the server.
I am pretty sure the Meteor server is running on OpenShift, because I saw something to that effect on the startup logs (via ssh). However, I am not sure how to connect to the Meteor server to test it.
The domain is nodejs-easyjobs.rhcloud.com (54.208.77.250) on the OpenShift server, I can ping this successfully.
I am using Ionic 2 to build the mobile app. I am currently just running on Android, but plan to add iOS and Windows.
I am following this tutorial, and it runs on localhost. However, I am not sure where this is configured. I guess localhost is default, and you need to change it to a different host if needs be.
If I check my OpenShift server (nodejs-easyjobs.rhcloud.com) via ssh, I can see that the contents of the Meteor bundle directory is on the server. So Git is pushing the code.
The part I don't understand is:
Do I need to configure Meteor differently for being on the OpenShift
Server? Or do I just leave it as is?
Where do I configure the client
(Ionic 2) to point to the OpenShift server?
Question:
My question is, how do I configure my mobile app (Ionic 2) to connect to the OpenShift Meteor Server?
UPDATE:
My dir structure:
openshift-appname
.../ionic-apps/nodejs/bundle/server/...
meteorapp
.../ionic-aps/myIonicApp/api/.meteor/...
.../ionic-aps/myIonicApp/api/server/...
The contents of the .../ionic-apps/nodejs is cloned on the OpenShift server with Git.
I followed this tutorial to deploy the Meteor bundle to OpenShift. `
So I used the following to build my Meteor app:
> cd .../ionic-aps/myIonicApp/
> meteor build .../ionic-apps/nodejs --directory --server-only
As far as I can see, I may be wrong, but the Meteor Server is all correct and running on OpenShift. I need to know how I can get my Ionic2 app to access it.
Step1: Find the access point to the Meteor server using the OpenShift
IP. i.e. nodejs-easyjobs.rhcloud.com (54.208.77.250).
Step2: Configure my Ionic2 client to use this.
I'm developing an app, using MEAN.js and its generator (https://github.com/DaftMonk/generator-angular-fullstack), and Openshift as a hosting.
The project template of the generator includes a script (server/config/seed.js) to populate the database with two users.
In localhost, it is called automatically, but I also can call it using node server/config/seed.js (suppose you're on the root app directory).
The problem is, when I deploy it to Openshift, I run it and no error is reported, but the mongodb database is not updated. The exactly steps I do to run it on Openshift are:
Connect to ssh: ssh ....
cd app-root/runtime/repo/
`node server/config/seed.js``
What am I missing?
Thanks in advance.
You have few options:
in server/config/production.js add
seedDB: true
or change NODE_ENV to development coz during 1st deployment it is set to production
then
grunt
grunt:buildcontrol:openshift
should be working now