- What is node-app-http-docker โ
- Project setup ๐ผ
- Running docker ๐
- Running docker Image ๐ฝ
- Testing (is it working) โ โ
- STOPPING docker (running container) ๐
- MIT LICENSE ๐ก๏ธ
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 |
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 have
docker
installed and running on your machine.
If not, its highly recomended to Get docker
docker build . -t node-app-http-docker
To know why we used
-t Allocate a pseudo-TTY
read this stackoverflow thread
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
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
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 |
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
node-app-http-docker was released under MIT License