To do below
i.e Get the number of Impressions.
and scale them as per need.
Same steps what we followed
https://automationknowledgesharing2020.blogspot.com/2020/08/dockerlearning.html
i.e
1.package.json
2.index.js
3.Dockerfile
Create new file
C:\Users\manjunathk\impressions>
add/create the below
Steps
docker build .
docker build -t manjunathk/impressions:latest .
docker run manjunathk/impressions
docker run redis
2 containers are isolated
Note: Get rid off Docker cli we shall use Docker Compose
services are type of container
2 services i.e redis and node-app inside docker-compose.yml file take the form of 2 different docker container
so create docker-compose.yml as below
index.js
const express = require("express");
const redis = require("redis");
const process = require("process");
const app = express();
const client = redis.createClient({
host: "redis-server",
port: 6379
});
client.set("visits", 0);
app.get("/", (req, res) => {
//process.exit(0)
client.get("visits", (err, visits) => {
res.send("Number of visits " + visits);
client.set("visits", parseInt(visits) + 1);
});
});
app.listen(8081, () => {
console.log("listening on port 8081");
});
Note:
If running container crashes, we can follow belowsteps,
No comments:
Post a Comment