GithubHelp home page GithubHelp logo

hello-docker-nodejs's Introduction

NodeJs app Docker locally on Windows 10 Home edition

Setup:

  1. Install Docker Desktop for Windows and Enable 'Use the WSL2 based engine..'
  2. Enable Kubernetes in Docker Desktop
  3. Install command line tools in WSL2

Build container and run from WSL

  1. To build the container run the following

docker build . -t hello-docker-nodejs

  1. Above lists the container id. Launch the container using the id

docker run -p 3000:3000 f5ec8a4a7ce2

  1. Visit the website using browser or run curl command.

  2. Stop docker (from another window) docker ps docker stop <container id>

  3. Prune everything... (CAUTION.. below removes everything from Docker including other projects and images). Do it only if needed... docker system prune -a

Use Kubernetes to run above container

Kube commands

  1. Get existing pods kubectl get pod - Get information about all running pods

  2. Create pod for the hello world nodejs app kubectl create -f kubernetes/helloworld.yml

Note: imagePullPolicy should be set to Never which forces kubernetes to use local image

  1. Create a service using command line for now. kubectl port-forward hello-docker-node 8080:3000

And test it by visiting localhost:8080 (curl or browser). ^C to exit the command line afterwords

  1. Expose the service kubectl expose pod hello-docker-node --type=NodePort --name=hello-docker-node-service The service is exposed. It will chose a random port from local host to forward the traffic to above container. Obtain the IP addres by running kubectl get services

Visit localhost:31828. Note that the port will be different and it is obtained from the kubectl get services command.

  1. Get more information about the service as follows kubectl describe service hello-docker-node-service

Important Kubectl commands

kubectl describe pod <pod>

kubectl expose pod <pod> --port=3000 --name=frontend - Creates a service

kubectl port-forward <pod> 8080 - Port forward the exposed pod port to your local machine

kubectl attach <pod> -i - Attach to pod

kubectl exec <pod> command - Execute a command on the pod

Kubernets - scalaing

Use kind: ReplicationController and provide replicas: n to create n number of pods

kubectl create -f helloworld-repl-controller.yml

kubectl get replicationController or kubectl get rc kubectl scale --replicas=4 rc/helloworld-controller

Delete the replication controller by kubectl delete rc/helloworld-controller

hello-docker-nodejs's People

Contributors

finecode avatar satishbabu avatar

Watchers

 avatar  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.