上QQ阅读APP看书,第一时间看更新
Running a receiver application on a PC
To run a receiver app on a PC, follow this sequence:
- Create the receiver folder.
- Create the ./receiver/package.json file with the following content:
{
"name": "receiver",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"start": "node index.js",
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC"
}
- Create the ./receiver/index.js file with the following content:
var http = require('http');
var querystring = require('querystring');
http.createServer(function (req, res) {
req.on('data', function (chunk) {
var data = querystring.parse(chunk.toString());
console.log(data);
});
req.on('end', function () {
res.writeHead(200, 'OK', {'Content-Type': 'text/html'});
res.end('Data received.')
});
}).listen(8080);
- Create the ./receiver/Dockerfile file with the following content:
FROM node:boron-onbuild
EXPOSE 8080
- Navigate to ./receiver.
- Build an image and run a Docker container:
# Build an image from a Dockerfile
docker build -t http-receiver .
# Run container in foreground
docker run -p 8080:8080 -it --rm --name http-receiver-container http-receiver
# Run container in background
# docker run -p 8080:8080 -d --rm --name http-receiver-container http-receiver
# Fetch the logs of a container
# docker logs -f http-sensor-container
# Stop running container
# docker stop http-receiver-container
Console output when a receiver application is running