Enable an Image to Be Parameterized in Docker

Create a .js file

var radius = process.env.diameter / 2;
var area = Math.pow(radius, 2) * Math.PI;
console.log(
    `Area of a ${radius} cm radius disk:
    ${area} cm²`
);

Create a file named Dockerfile and add the following code to it:

FROM node:11-alpine

ENV diameter=4.0

COPY compute.js .

CMD node compute.js

Open a command-line. Change the current directory to the directory where you created the Dockerfile and the compute.js file.

The following command will build your docker image.

docker build -t jsparam .

Run the following command once the image has been built, it will start the container and run your images.

docker run --rm jsparam
docker run --rm -e diameter=5.0 jsparam