Assuming you already have a basic knowledge of Node.jS and Docker.
If you need support of how to install & get started with Node.JS & Docker then you can check their official documentations.
For Node.JS I've used npm but you can use Yarn which is a quicker way to manage your Node.JS dependencies & packaging.
Likewise for Docker you can get the software & installation steps here for your OS.
This is a very basic dev/local setup to demonstrate how to get your Node.JS app published on Docker Hub and run using basic Docker commands. Will try to cover other areas like Kubernets, automation in a much wider sense in separate post.
For my example I'm using a simple ReactJS web app.
Modify/update your web app with whatever functionality that you need to implement.
My app is a simple SPA with a form and lists users by calling a microservice API (simple API call using JQuery). Not very fancy but just to show case/setup. http://localhost:3000/#
Add a .dockerignore file in the same directory as your Dockerfile. I've added following files to be ignored, but you can choose what you want not to package;
You can check your image by doing the following;
If all well then it should list down
If you want to check status docker ps, docker logs
If you need support of how to install & get started with Node.JS & Docker then you can check their official documentations.
For Node.JS I've used npm but you can use Yarn which is a quicker way to manage your Node.JS dependencies & packaging.
Likewise for Docker you can get the software & installation steps here for your OS.
This is a very basic dev/local setup to demonstrate how to get your Node.JS app published on Docker Hub and run using basic Docker commands. Will try to cover other areas like Kubernets, automation in a much wider sense in separate post.
For my example I'm using a simple ReactJS web app.
Create RactJS app & test your ReactJS app locally first (though not the focus of this post, but a quick recap);
$ npm install -g create-react-app //install create react app $ create-react-app frontend //create your app $ cd froentend $ npm start //start & test
Modify/update your web app with whatever functionality that you need to implement.
My app is a simple SPA with a form and lists users by calling a microservice API (simple API call using JQuery). Not very fancy but just to show case/setup. http://localhost:3000/#
Dockerizing
First create a file with name Doclerfile in your ReactJS root directory.
Then open the file in any text editor and add following;
FROM node:boron # MAINTAINER manmohanpanda # Prepare app directory RUN mkdir -p /usr/src/app ADD . /usr/src/app # Install dependencies WORKDIR /usr/src/app # Install app dependencies COPY package.json . RUN npm install COPY . . # Build the app RUN npm build # Expose the app port EXPOSE 3000 # Start the app CMD npm start
Add a .dockerignore file in the same directory as your Dockerfile. I've added following files to be ignored, but you can choose what you want not to package;
.git .gitignore .editorconfig node_modules *.log *.md
Building the Docker image
Run following from the project root directory in your shell;
docker build -t <your username>/newway-frontend .
You can check your image by doing the following;
$ docker images
If all well then it should list down
$ docker images REPOSITORY TAG IMAGE ID CREATED SIZE manmohanpanda/newway-frontend latest 961c7c38431b About an hour ago 793MB
Run & Test the Docker image
Run the image using following;$ docker run -p 49160:3000 -d <your username>/newway-frontend
If you want to check status docker ps, docker logs
Publish the Docker image to Docker Hub
$ docker push manmohanpanda/newway-frontend
Useful post, I would like to read more about reactjs. Share more like this.
ReplyDeleteReact js course | React js certification
This blog is unique from all others. Thanks for sharing this content in an excellent way. Waiting for more updates.
ReplyDeleteSpoken English Class in Anna Nagar
Spoken English Classes in Chennai Anna Nagar
Spoken English Classes in Anna Nagar West
Spoken English Classes in Chennai
Best Spoken English Classes in Chennai
Spoken English Class in Chennai
Spoken English in Chennai
English Classes in Chennai
I would definitely thank the admin of this blog for sharing this information with us. Waiting for more updates from this blog admin.
ReplyDeleteTally Course in Chennai
ReactJS Training in Chennai
microsoft dynamics crm training in chennai
ui design course in chennai
microsoft dynamics training
gst training classes in chennai
Thank you for uploading such a wonderful content on recent technology.
ReplyDeleteHadoop Training in Chennai
Big data training in chennai
Big Data Hadoop Training in Chennai
JAVA Training in Chennai
Python Training in Chennai
Digital Marketing Course in Chennai
Hadoop training in chennai
Big data training in chennai
big data training in velachery
Nice work, your blog is concept-oriented, kindly share more blogs like this
ReplyDeleteReact js Online Training
Angular Training
NodeJS Online Training Hyderabad
Angular Training
Informative blog and useful information for all users. Keep sharing more blogs with us.
ReplyDeleteOnline UI Development Course in Hyderabad
Online RPA Course in Hyderabad
Online Python Course in Hyderabad
Online Mean Stack developer Course in Hyderabad