Search⌘ K
AI Features

Exercise: Build an Image and Run It

Explore building a Docker image that executes a Node.js script calculating the area of a disk. This exercise guides you through writing a Dockerfile using the node:11-alpine base image, helping you understand essential Docker image creation and execution steps.

We'll cover the following...
svg viewer

Create a file named compute.js with the following code that computes and displays the area of a disk using JavaScript:

Javascript (babel-node)
var radius = 2.0;
var area = Math.pow(radius, 2) * Math.PI;
console.log(
`Area of a ${radius} cm disk:
${area} cm²`
);

svg viewer

Create a Docker image that runs the code in compute.js file using the node:11-alpine ...