Dockfile for V5
I downloaded the V5 and added a Dockerfile under the root directory like below. It threw me the following error when trying to create a docker image and publish it to Azure container registry. Any thoughts?
Dockerfile:
FROM node:18
WORKDIR /usr/src/app
COPY package*.json ./
RUN npm install
COPY . .
EXPOSE 8080
CMD ["node", "bin/cli.js", "--enableServer", "1", "--port", "8080"]
CLI commands:
az acr build --file Dockerfile --registry 1mapdevacr --image bphighcharts:v5 .
Error:
.
.
Step 4/7 : RUN npm install
---> Running in 76a87b1e9f44
npm warn deprecated [email protected]: Rimraf versions prior to v4 are no longer supported
npm warn deprecated [email protected]: This module is not supported, and leaks memory. Do not use it. Check out lru-cache if you want a good and tested way to coalesce async requests by a key value, which is much more comprehensive and powerful.
npm warn deprecated [email protected]: Glob versions prior to v9 are no longer supported
npm warn deprecated @humanwhocodes/[email protected]: Use @eslint/config-array instead
npm warn deprecated @humanwhocodes/[email protected]: Use @eslint/object-schema instead
> [email protected] install
> node ./install.js
node:internal/modules/cjs/loader:1143
throw err;
^
Error: Cannot find module '/usr/src/app/install.js'
at Module._resolveFilename (node:internal/modules/cjs/loader:1140:15)
at Module._load (node:internal/modules/cjs/loader:981:27)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:128:12)
at node:internal/main/run_main_module:28:49 {
code: 'MODULE_NOT_FOUND',
requireStack: []
}
Node.js v18.20.8
npm error code 1
npm error path /usr/src/app
npm error command failed
npm error command sh -c node ./install.js
npm notice
npm notice New major version of npm available! 10.8.2 -> 11.3.0
npm notice Changelog: https://github.com/npm/cli/releases/tag/v11.3.0
npm notice To update run: npm install -g [email protected]
npm notice
npm error A complete log of this run can be found in: /root/.npm/_logs/2025-04-28T17_46_54_998Z-debug-0.log
The command '/bin/sh -c npm install' returned a non-zero code: 1
2025/04/28 17:47:24 Container failed during run: build. No retries remaining.
failed to run step ID: build: exit status 1
Run ID: cgnc failed after 1m2s. Error: failed during run, err: exit status 1
Run failed
Feel free to use this Dockerfile which I created for my own purposes. It uses a real chromium browser instead of puppeteers build in version and applies some work-arounds to let chromium run in a dockerized environment. It is mostly based on this article: https://www.digitalocean.com/community/tutorials/build-a-puppeteer-web-scrapper-with-docker-and-app-platform
The cache-init step is optional, but is very helpful in environments where outbound network traffic is not allowed. It also speeds up the start-up time.
FROM node:18-alpine
# Install system dependencies required by Puppeteer and fonts
RUN apk add --no-cache \
chromium \
nss \
freetype \
freetype-dev \
harfbuzz \
ca-certificates \
ttf-freefont \
ttf-dejavu \
fontconfig \
dumb-init
# Tell Puppeteer to use the installed Chromium
ENV NODE_ENV=production
ENV PUPPETEER_SKIP_CHROMIUM_DOWNLOAD=true
ENV PUPPETEER_EXECUTABLE_PATH=/usr/bin/chromium-browser
WORKDIR /app
RUN npm install -g highcharts-export-server
COPY config.json /app/config.json
RUN addgroup -g 500 -S nodejs && \
adduser -S application-user -u 500
# Create directories for tmp and cache files
# Create symbolic links to fix known issues
# the cachePath directive in config.json file seems not to work as expected
RUN mkdir -p /app/tmp /app/.cache p /app/ssl && \
ln -sf /app/.cache /usr/local/lib/node_modules/highcharts-export-server/.cache && \
chown -R application-user:nodejs /app
USER application-user
# Prefill caches
RUN echo "Prefilling caches..." && \
export PUPPETEER_EXECUTABLE_PATH=/usr/bin/chromium-browser && \
echo '{"chart":{"type":"line"},"series":[{"data":[1,2,3,4,5]}]}' > /tmp/chart.json && \
highcharts-export-server --enableServer false --infile /tmp/chart.json --outfile /tmp/test.png --type png --loadConfig /app/config.json && \
rm -f /tmp/chart.json /tmp/test.png && \
echo "Cache prefill completed"
EXPOSE 7801
ENTRYPOINT ["dumb-init", "--"]
CMD ["highcharts-export-server", "--loadConfig", "/app/config.json", "--enableServer", "true"]
here is the config.json file which is used within the Dockerfile:
{
"puppeteer": {
"args": [
"--no-sandbox",
"--disable-setuid-sandbox",
"--disable-dev-shm-usage",
"--disable-accelerated-2d-canvas",
"--no-first-run",
"--disable-gpu",
"--disable-background-timer-throttling",
"--disable-backgrounding-occluded-windows",
"--disable-renderer-backgrounding",
"--disable-features=TranslateUI",
"--disable-ipc-flooding-protection"
],
"tempDir": "/app/tmp/"
},
"highcharts": {
"version": "12.1.2"
},
"pool": {
"minWorkers": 1,
"maxWorkers": 2,
"acquireTimeout": 30000,
"createTimeout": 30000,
"destroyTimeout": 15000
},
"logging": {
"level": 3,
"file": "highcharts-export-server.log",
"dest": "log/",
"toConsole": true,
"toFile": false
}
}