I’ve been evaluating Verdin iMX8M-Mini Dula Lite and I’d like runnign a nodejs application in a Docker container over Torizon.
Is it technically feasible (flash and memory constrains)?
Is it available a Docker container with nodejs installed?
Hi @vix !
The containers made available by Toradex are usually meant to leverage hardware-specific features (like GPU for those modules that have it).
For the “application-only layer”, there are containers available via usual channels (like Dockerhub, Github, etc).
So, for example, you can go directly to Dockerhub and use the official Node container from there. You just need to be sure to select containers that support that target architecture (it is ARM 64 for iMX8-based modules).
And, about memory constraints, it depends on what you will use. Most probably your application will not need only node.js, but some other useful packages as well. So you will need to manage the memory (RAM and flash) usage as well.
Another remark: you might want to get rid of some of the default containers images that you might have in your TorizonCore (portainer, kiosk, weston) to save some space.
Best regards,
Hi @henrique.tx
I try to describe what I did and where I got stopped.
I started with TorizonCore with evaluation containers from here.
I saw there are some containers (portainer, kiosk and weston-vivante:2).
I try to install nodejs and all the necessary dependencies directly in weston-vivante container but (of course) we run out of space.
So I need to explore and find different solution to get the desired target, which is run my nodejs-based application on the Verdin iMX8M-Mini.
As far as I understand, this should be possible replacing portainer container with a nodejs-application container (which exposes a web app server), so that kiosk container can render my application through the included chromium.
Can you confirm that this is the correct way to get the result?
And, if yes, can you suggest how to proceed?
Thanks in advance
Hi @vix!
About this part:
Seems like you are talking about flash, right? Could you elaborate on what steps you executed to use all the flash space? Also, which Verdin iMX8 M Mini are you using? Their flash goes from 4GB to 16GB (and RAM from 1GB to 2GB):
Also, please refer to Node’s best practices at GitHub - nodejs/docker-node: Official Docker Image for Node.js 🐢.
Best regards,
Henrique
Quick Node.js example
I created a quick Node hello world and below are the flash and RAM usage when running Weston, Kiosk, and the Node.js app (based on official Node container). This by no means represents a Node.js template to follow! This was solely used to quickly test the memory (RAM/flash) usage.
Module | OS |
---|---|
Verdin iMX8M Mini Q 2GB WB IT V1.1A | TorizonCore 5.5.0 |
RAM
verdin-imx8mm-06827711:~$ free -m
total used free shared buff/cache available
Mem: 1977 575 119 51 1283 1283
Swap: 0 0 0
Flash
verdin-imx8mm-06827711:~$ df
Filesystem 1K-blocks Used Available Use% Mounted on
tmpfs 1012576 22028 990548 3% /run
devtmpfs 743968 0 743968 0% /dev
/dev/disk/by-label/otaroot 15226760 2974372 11459200 21% /sysroot
tmpfs 1012576 0 1012576 0% /dev/shm
tmpfs 1012576 0 1012576 0% /sys/fs/cgroup
tmpfs 1012576 16220 996356 2% /tmp
tmpfs 1012576 8 1012568 1% /var/volatile
tmpfs 202512 0 202512 0% /run/user/1000
The node container setup and docker-compose.yml and how to launch it:
app.js
/home/torizon/node-app/app.js
const express = require('express')
const app = express()
app.get('/', (req, res) => res.send('Hello World!'))
app.listen(3000, () => console.log('Server ready'))
var process = require('process')
process.on('SIGINT', () => {
console.info("Interrupted SIGINT")
process.exit(0)
})
process.on('SIGTERM', () => {
console.info("Interrupted SIGTERM")
process.exit(0)
})
package.json
/home/torizon/node-app/package.json
{
"name": "node-app",
"version": "1.0.0",
"description": "",
"main": "app.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"express": "^4.17.3"
}
}
The 3 files above must be used to build the Docker image from the Dockerfile
below.
Dockerfile
/home/torizon/node-app/Dockerfile
#to build: docker build -t node-app /home/torizon/node-app
FROM node
WORKDIR /usr/src/app
COPY package*.json app.js ./
RUN npm install
EXPOSE 3000
CMD ["node", "app.js"]
After building the Docker image, we can launch Weston, Kiosk and our hello-world Node.js app using the following docker-compose.yml
.
docker-compose.yml
/home/torizon/docker-compose.yml
version: '2.4'
services:
node-app:
command: node app.js
image: node-app
ports:
- 3000:3000
kiosk:
command: http://node-app:3000
depends_on:
node-app:
condition: service_started
weston:
condition: service_started
image: torizon/kiosk-mode-browser@sha256:97130d7d2bb0c18180d3e0b8aa7af3c68a99ce0b50afb3caeaca849b45e8e99e
platform: linux/arm64
security_opt:
- seccomp:unconfined
shm_size: 256mb
volumes:
- source: /tmp
target: /tmp
type: bind
- source: /var/run/dbus
target: /var/run/dbus
type: bind
weston:
cap_add:
- CAP_SYS_TTY_CONFIG
device_cgroup_rules:
- c 4:0 rmw
- c 4:7 rmw
- c 13:* rmw
- c 199:* rmw
- c 226:* rmw
environment:
ACCEPT_FSL_EULA: '1'
image: torizon/weston-vivante@sha256:827417ba996cf20c4676bae19c0128e8ea27f41a620dd0b84174427f06779797
network_mode: host
volumes:
- source: /tmp
target: /tmp
type: bind
- source: /dev
target: /dev
type: bind
- source: /run/udev
target: /run/udev
type: bind
How to launch
To watch outputs from the containers
docker-compose -f /home/torizon/docker-compose.yml up
To launch in detached mode (no output to the terminal)
docker-compose -f /home/torizon/docker-compose.yml up -d
After some attempts I was able to get a docker container with nodejs running in Torizon.
- I started with a nexts project
- I followed the steps here
- I cross-compiled for ARM64 architecture
- I deployed to Torizon
- I can see the UI using the chromium container included in Torizon with evaluation containers
Thanks
Hi @vix !
Great to know that it is working for you!
If possible, could you elaborate on what was the memory problem that you were facing?
Also, if your problem is solved, please mark the suitable message as solution.
Best regards,
The original “out of space” problem refers to Flash.
I tried to install nodejs in an existig container (as I do on my own Linux Desktop if I want to install nodejs).
The solution is to start from a working nodejs container.
You (@henrique.tx) suggested to start from the official node container - and I’m sure it works
I took a different way and followed th steps here to build a nextjs docker container on my Linux Desktop (and then cross-compiling it for ARM64 architecture)
Thanks for the explanation, @vix
It will surely help other users trying to do something similar