Skip to content

mbluecoder/node-app

Repository files navigation

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      node-app-http-docker

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

About

Simple RESTApi

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published