< Docker
Dockerfile
# Configures a Node runner and copies the current folder content
# to use as the program source.
# Use the following commands to build and run the server.
# docker build -t node-runner .
# docker run --rm node-runner
FROM node:alpine
WORKDIR /usr/src/app
COPY . .
CMD ["node", "app.js"]
app.js
// Displays "Hello world!"
//
// References:
// https://www.w3schools.com/jsref/met_console_log.asp
console.log("Hello world!");
Try It
Online Free
- Use Play with Docker. Create an account and/or log in.
- Start an interactive session and add a new instance.
- In the terminal window, enter the following commands:
touch Dockerfile
touch index.js
- Use the
Editor
button to edit both files and save the contents above into each respective file. - Run the following commands:
docker build -t node-runner .
docker run --rm node-runner
On Your Own System
- Install Docker Desktop or the Docker Engine.
- Save the files above into a new
Docker Node
folder:Dockerfile
index.js
- At a command prompt, change to the
Docker Node
folder and then run the following commands:docker build -t node-runner .
docker run --rm node-runner
See Also
This article is issued from Wikiversity. The text is licensed under Creative Commons - Attribution - Sharealike. Additional terms may apply for the media files.