Docker/Node.js
Appearance
< Docker
Dockerfile
[edit | edit source]# 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
[edit | edit source]// Displays "Hello world!"
//
// References:
// https://www.w3schools.com/jsref/met_console_log.asp
console.log("Hello world!");
Try It
[edit | edit source]Online Free
[edit | edit source]- 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
[edit | edit source]- 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