Use Node.js to display hello world on the console
Use Visual Studio Code (hereinafter VSCode) Use Node.js container with Docker
Install Docker, a VScode extension, in advance. (* 2)
Nodejs-sample-app (any folder name is fine) folder.
docker-compose.yml file under it.
This is a standard file when downloading a container to docker, so the file name is fixed. A yml file is a text file written according to the YAML format, and is used for data transfer.
This time, it is described as follows.
version: "3" services: node: image: node:14.15 volumes: - .:/project tty: true working_dir: /project command: bash
Meaning of each item
Using the terminal function of VSCode, enter the
Nodejs-sample-app folder and type the following command to download Node.js to docker.
docker-compose up -d
I opened docker and it looks like this!
Select Attach shell to enter the container (see photo)
You can switch between the local terminal and the container terminal here
app.js file in the same hierarchy as
This time it is described as follows
At the terminal inside the container
$ node app.js
When you type the command and the following is displayed, Node.js environment construction is complete! ![スクリーンショット_2021-01-16_12_47_28.jpg](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/663834/a2844d6f-68de-12c5-7c35-d6baf8f095fb.jpeg)