Exercise: Enable an Image to Be Parameterized
Test yourself and implement what you have learned so far in this exercise.
In the create-docker-images/exercises/jsparam/starter folder you’ll find a compute.js file with the following code:
It’s a modified version of the code from the previous exercises. It expects a diameter
environment variable to be available and displays the area of a disk for that given diameter. Create a Docker image that runs the code in compute.js
file using the node:11-alpine image that contains Node.JS. Run two containers with different values for the diameter.
The base image is already provided for you in both of the following cases. Write the additional commands to complete the Dockerfiles. You don’t have to worry about writing the commands to build and run the Dockerfile as they will be executed automatically when the RUN button is pressed.
Running the docker commands in the following widget will fetch the value of the environment variable from the Dockerfile.
/
- Dockerfile
Running the docker commands in the following widget will fetch the value of the environment variable from the command used to run the Dockerfile.
/
- Dockerfile
The source code for the solution can be found in the create-docker-images/exercises/jsparam/solution folder.
Let’s go over the solution in the next lesson.