Git Product home page Git Product logo

node-app-http-docker's Introduction

node-app-http-docker

Table of Contents

  1. What is node-app-http-docker โ“
  2. Project setup ๐Ÿ’ผ
  3. Running docker ๐Ÿ‹
  4. Running docker Image ๐ŸŽฝ
  5. Testing (is it working) โœ… โŽ
  6. STOPPING docker (running container) ๐Ÿ›‘
  7. MIT LICENSE ๐Ÿ›ก๏ธ

What is node-app-http-docker โ“

It is a working project (non Prod ready)

For getting started with a RESTFUL api server locally using docker

  • It ๐Ÿƒruns a server (docker) using nodejs [v16]
  • Exposes following RESTFUL endpoints ( no database required) with all CRUD operations
Rest API call CRUD operation REST endpoints
GET Read http://0.0.0.0:8080/
http://0.0.0.0:8080/health
http://0.0.0.0:8080/api/todos
http://0.0.0.0:8080/api/todos/{id}
PATCH/PUT Update) http://0.0.0.0:8080/api/todos/{id}
POST {with body} Create http://0.0.0.0:8080/api/todos
DELETE Delete http://0.0.0.0:8080/api/todos/{id}
  • You may get 3 types of response
Response Code Response Status
200 OK
201 Created
404 Not Found

Project setup ๐Ÿ’ผ

Clone the repository on your machine

Using Comand
via https git clone https://github.com/eaccmk/node-app-http-docker.git
via ssh git clone [email protected]:eaccmk/node-app-http-docker.git
cd node-app-http-docker

๐Ÿ’ก Prequisite / Assumption

  • You havedocker installed and running on your machine.

If not, its highly recomended to Get docker

Running docker ๐Ÿ‹

docker build . -t node-app-http-docker

To know why we used -t Allocate a pseudo-TTY read this stackoverflow thread

Verify docker Image ๐Ÿ–ผ๏ธ

After docker build is completed, verify if a docker image is created and listed

run docker images

docker images
REPOSITORY                      TAG         IMAGE ID      CREATED         SIZE
localhost/node-app-http-docker  latest      8f74146744df  18 minutes ago  928 MB

You may have more than one row in result, but make sure you have the one with REPOSITORY localhost/node-app-http-docker

also see you got a random (uniqie) IMAGE ID assigned to the image you just created, in my case it was 8f74146744df

Running docker Image ๐ŸŽฝ

Now that you have a IMAGE ID, lets run that image

docker run -p 8080:8080 8f74146744df

docker run -p <your-port-external>:<docker-internal-port-exposed-for-access> IMAGE_ID

For more details on -p read **Publish or expose port (-p, --expose)**๐Ÿ”—

โ— open a new tab on terminal and verify this docker (running)

docker ps

Testing (is it working โœ… โŽ)

Lets hit the docker image as a client / User

Test Type (Positive /Negative) CLIENT On terminal Response SERVER (if Docker running with logs)
โœ… Home Page curl 0.0.0.0:8080 Welcome, this is your Home page CalledGET : /
โŽ Invalid endpoint http://0.0.0.0:8080/dascbajb {"message":"Route not found"} CalledGET : /dascbajb
This endpoint is not implemented / unavailable at the moment !!
โœ… health check http://0.0.0.0:8080/health {"uptime":29.560686169,
"message":"OK","timestamp":1644057630652}
CalledGET : /health

STOPPING docker (docker container) ๐Ÿ›‘

firts lets find the runing one docker ps

CONTAINER ID  IMAGE                                  COMMAND      CREATED            STATUS                 PORTS                   NAMES
a5a149a53466  localhost/node-app-http-docker:latest  node app.js  About an hour ago  Up About a minute ago  0.0.0.0:8080->8080/tcp  ecstatic_cray

see the status column : STATUS

Up About a minute ago

Stop using ๐Ÿ‘‰ 1.CONTAINER ID shell docker stop a5a149a5346

2.NAMES shell docker stop ecstatic_cray

In case you want to confirm ---->> run docker ps it should show no running image

docker ps
CONTAINER ID  IMAGE       COMMAND     CREATED     STATUS      PORTS       NAMES

License ๐Ÿ”ฐ

node-app-http-docker was released under MIT License

node-app-http-docker's People

Contributors

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