Coder Social home page Coder Social logo

gokuld6012 / docker-node-app Goto Github PK

View Code? Open in Web Editor NEW

This project forked from nanofaroque/docker-node-app

0.0 1.0 0.0 1.49 MB

This is a basic node application build on docker container. Details of this project is to explain from scratch.

JavaScript 86.87% CSS 2.95% HTML 7.31% Dockerfile 2.87%

docker-node-app's Introduction

Introduction

Docker is container runs as a guest operating system. It is pretty similar like VM but vm does not share their resources with other vm. On the other hand container share their resources with other container on same host machine.

How to run your node app to docker

First build a node app with express generator like below:

create a directory
mkdir docker-node-test
Go the project directory
cd docker-node-test
Install express generator globally
npm install -g express-generator
Create your express app
express -f
create a docker file
touch Dockerfile

Now update your docker file based on your requirements. Here is mine

FROM node:7
WORKDIR /app
COPY package.json /app
COPY . /app
RUN npm install
CMD ["npm", "start"]
EXPOSE 4000

Here is the explanations of the above code base

FROM node:7
-- You are telling to docker to get node 7 to build your project from wherever
docker knows where to get it.
WORKDIR /app
-- Create a directory inside of the container called "app"
COPY package.json /app
-- copy your local package.json to the containers app directory
COPY . /app
-- Copy your whole applications to the app folder/direcoty of the container
RUN npm install
-- Run npm install to fetch all the project dependency
CMD ["npm", "start"]
-- Start your node application.
EXPOSE 4000
-- You are exposing the application port to outside of the container

Build your application container

docker build -t your-tag-for-the-applications .

-t is used to tag the app

Run your application container

docker run -p your-host-machine-port:your-exposed-port-from-docker YourAppName

Inspect your app

docker ps yourappname

Sharing docker image

First Singup an account at hub.docker.com

Now build the app again for your docker account

docker build -t [your-docker-hub-username]/yourProjectName

Now login to your docker hub account:

docker login

Enter your user name and password

Now push your code to docker hub.

docker push [your-dockerhub-username]/yourProjectName

Now you can run your docker image on any server or PC with docker installed

Get the image from docker hub
docker pull
Run the image
docker run [your-dockerhub-username]/yourProjectName

Removing all the container and Images

List all containers (only IDs)

Stop all running containers

docker stop $(docker ps -aq)

Remove all containers

docker rm $(docker ps -aq)

Remove all images

docker rmi $(docker images -q)

docker-node-app's People

Contributors

nanofaroque avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.