Posted by : at

Category : javascript   node   kubernetes   devops   docker

Kubernetes and Docker

Dockerfile cat > Dockerfile << EOF

    # Use an official Node runtime as the parent image

    FROM node:6

    # Set the working directory in the container to /app

    WORKDIR /app

    # Copy the current directory contents into the container at /app

    ADD . /app

    # Make the container's port 80 available to the outside world

    EXPOSE 80

    # Run app.js using node when the container launches

    CMD ["node", "app.js"]

    EOF

Now create the node server file :

app.js cat > app.js <<EOF


    const http = require('http');

    const hostname = '0.0.0.0';

    const port = 80;

    const server = http.createServer((req, res) => {

        res.statusCode = 200;

          res.setHeader('Content-Type', 'text/plain');

            res.end('Hello World\n');

    });

    server.listen(port, hostname, () => {

        console.log('Server running at http://%s:%s/', hostname, port);

    });

    process.on('SIGINT', function() {

        console.log('Caught interrupt signal and will exit');

        process.exit();

    });

    EOF

Related Posts