Nodegrid linux distribution have docker application pre-installed.
Verification can be done with "docker --version" command in the root shell of the Nodegrid.
Note: Nodegrid requires licensing to enabled to run the containers in Nodegrid appliance
In this example, using express to service the webpage within the Nodegrid. Since the Nodegrid is using the 443 port for the Nodegrid Manager application, the express page will be using the port 4000 for web service.
For this container to run, Node is required in the Linux disctribution. using command "node --version" to determined if Node is in the system.
Step 1: from the Nodegrid root shell, create a folder for the container. example "mkdir testexpress". Go into the created folder "cd testexpress"
Step 2: execute "npm install" from within the folder. This command will create package.json file
Step 3: execute "npm install --package-lock" will generate package-lock.json file
- The package.json should have:
- {
- "name": "testDock",
- "version": "1.0.0",
- "description": "",
- "main": "index.js",
- "scripts": {
- "test": "echo \"Error: no test specified\" && exit 1"
- },
- "keywords": [],
- "author": "",
- "license": "ISC",
- "dependencies": {
- "express": "^4.17.1"
- }
- }
The package-lock.json should be left as is.
Step 4: Create a folder "mkdir src" inside of the example "testexpress" folder.
Step 5: Create "server.js" file in the testexpress/src folder. The server.js contains
- {
- "name": "testDock",
- "version": "1.0.0",
- "description": "",
- "main": "src/server.js",
- "scripts": {
- "start": "node src/server.js"
- },
- "keywords": [],
- "author": "Son Nguyen",
- "license": "ISC"
- }
Step 6: Create a file "app.js" in the "testexpress/src" folder. The app.js contains
- const express = require('express')
- const app = express()
- app.get('/', (req, res) => res.send('Hello World! This is Son Test'))
- app.listen(4000, () => console.log('Server ready'))
Step 7: Build this docker image and register it to docker
- docker build -t appname:tagname dir
For this example: "docker build -t testexpress:1.0 ." can be used to create this docker image.
The build process can take up to a few minutes. Example output
Step 8: "docker images" command be used to see the images registered in docker.
Step 9: The images is now in docker to run this image
- docker run -d -p 4000:4000 testexpress:1.0 .
The -d option is to detached the current shell from the executed container.
The -p option is port exposed in the Dockerfile to access the webpage this container is servicing
Step 10: using the "docker ps -a" to see all the current running containers
Step 11: The container is currently running, to access the container webpage, open a browser with "http://<nodegrid management ip>:4000
The results showed the container express web service replied
Step 12: Stopping the container with "docker stop <CONTAINER ID>". Use the "docker ps -a" to get the container id
Step 13: The container can be removed from docker "docker rmi -f <image id>". The image id can be retrieved from the "docker images" command