Nodejs/NPM-Setup in Docker Container fails (wrong version / NPM not found)

I’m maintaining an old laravel project coming form laravel 6, running in dev-environment in a docker-container with php 7.4, nodejs12, elasticsearch and mariadb. The project shall be upgraded to newer versions. Obviously, I’m a newbie to docker and struggling a bit. Upgrading to Laravel 7 and Laravel 8 incl package-dependencies worked well. Starting the predefined docker environment shows the decrepation warning because of Nodejs12, but the project ran stable. Somehow, I messed things up while upgrading to php 8.2 and Laravel 9 and stuck for several days.

What I did:

  1. Upgrade php-version and all package dependencies in my composer.json and run composer update. Composer successes with no conflicts, no vulnerabilities. Working through all relevant upgrade guides of all dependencies and updating my code.

  2. Updating the docker configuration for php8.2. I intended to only update php-version while running decrepated nodejs12-version in dev and upgrading it later.

My docker-compose.yml:

services:
  php-apache:
    volumes:
      - '.:/app'
      - './docker/${ENV}/php-apache/docker-config:/docker-config'
      - './docker/${ENV}/php-apache/docker-data-init:/docker-data-init'
      - './docker/${ENV}/php-apache/docker-helper:/docker-helper'
      - './docker/${ENV}/php-apache/docker-resources:/docker-resources'
      - './docker/${ENV}/php-apache/entrypoint.d:/entrypoint.d'
      - './docker/${ENV}/php-apache/etc/crontab:/etc/crontab'
    ports:
      - '80:80'
    environment:
      - ENV=${ENV}
      - WEB_DOCUMENT_ROOT=/app/public

My docker-compose.dev.yml:

services:
  php-apache:
    image: webdevops/php-apache-dev:8.2
    links:
      - mariadb
      - elasticsearch
  mariadb:
    image: 'mariadb:10.3.13'
    volumes:
      - './docker/${ENV}/mariadb/docker-config:/docker-config'
      - './docker/${ENV}/mariadb/docker-data-init:/docker-data-init'
      - './docker/${ENV}/mariadb/docker-helper:/docker-helper'
      - './docker/${ENV}/mariadb/docker-resources:/docker-resources'
      - './docker/${ENV}/mariadb/entrypoint.d:/entrypoint.d'
      - './docker/${ENV}/mariadb/var/lib/mysql:/var/lib/mysql'
    environment:
      - MYSQL_ROOT_PASSWORD=docker
  phpmyadmin:
    image: 'phpmyadmin/phpmyadmin'
    ports:
      - '8080:80'
    links:
      - 'mariadb:db'
    environment:
      - UPLOAD_LIMIT=1G
  elasticsearch:
    image: elasticsearch:7.4.0
    ports:
      - '9200:9200'
      - '9300:9300'
    environment:
      - discovery.type=single-node
  adminer:
    image: 'adminer'
    ports:
      - '8090:8080'

Inside projects-directory docker/dev/php-apache/entrypoint.d are the following config files (all files in one code block just to tidy it up a bit in my post):

#file: 100_helper.sh
#!/usr/bin/env bash

echo "alias ll='ls -la'" >> /root/.bashrc
echo "alias art='php artisan'" >> /root/.bashrc

#file: 200_extensions_system.sh
#!/usr/bin/env bash

apt-get update
apt-get install -y gnupg2


#file: 210_extensions_node.sh
#!/usr/bin/env bash

# Install Node.js version 12
curl -sL https://deb.nodesource.com/setup_12.x | bash -
apt-get install -y nodejs

echo "Node-Version inside Docker-Container: " && node -v
echo "NPM-Version inside Docker-Container: " && npm -v


#file: 220_extentions_sqlsrv.sh
#!/usr/bin/env bash

export DEBIAN_FRONTEND=noninteractive
export ACCEPT_EULA=Y
curl https://packages.microsoft.com/keys/microsoft.asc | apt-key add -
curl https://packages.microsoft.com/config/ubuntu/18.04/prod.list > /etc/apt/sources.list.d/mssql-release.list
apt-get update -y
apt-get install -y msodbcsql17 unixodbc unixodbc-dev

pecl install sqlsrv-5.10.1
echo 'extension=sqlsrv.so' >> /usr/local/etc/php/conf.d/sqlsrv.ini

pecl install pdo_sqlsrv-5.10.1
echo 'extension=pdo_sqlsrv.so' >> /usr/local/etc/php/conf.d/pdo_sqlsrv.ini


#file: 300_dependencies_php.sh
#!/usr/bin/env bash

if [ -f /app/composer.json ]; then
    composer install -d /app
fi


#file:310_dependencies_js.sh
#!/usr/bin/env bash

if [ -f /app/package.json ]; then
    npm --prefix /app install
    npm --prefix /app run dev
fi

I run my project with:

export ENV=dev && docker-compose -f docker-compose.yml -f docker-compose.dev.yml up -d

Note: I only changed my php-version in docker_compose.yml. I did not touch the docker/dev/-configfiles shown above. The shown configuration worked well with php 7.4, laravel 6-8. After switching to php8.2, the apache-docker-container crashes.

While executing the 210_extentions_node.sh, it stops at the last line with npm - command not found. Although nodejs12 source was loaded and installed, nom has not been installed with it. When removing the last line (num-command) in 210_extentions_node.sh, docker files while executing the 310_dependencies_ja.sh when trying to run npm --prefix /app install with same error: npm - command not found

Conclusion: npm is not loaded into the container anymore.

  1. As workaround, I tried to install npm separately: apt-get install -y nodejs npm

npm installation works, but I get a strange result:

Node-Version inside Docker-Container:
v18.19.0
NPM-Version inside Docker-Container:
9.2.0

(…)
Executing /entrypoint.d/310_dependencies_js.sh

added 60 packages, and audited 1267 packages in 13s

6 packages are looking for funding
run npm fund for details

153 vulnerabilities (3 low, 61 moderate, 54 high, 35 critical)

To address issues that do not require attention, run:
npm audit fix

To address all issues (including breaking changes), run:
npm audit fix –force

Run npm audit for details.

dev
npm run development

development
cross-env NODE_ENV=development node_modules/webpack/bin/webpack.js –progress –hide-modules –config=node_modules/laravel-mix/setup/webpack.config.js

10% building modules 7/10 modules 3 active …?ref–4-0!/app/resources/js/charts.jsnode:internal/crypto/hash:69
this[kHandle] = new _Hash(algorithm, xofLen);
^

Error: error:0308010C:digital envelope routines::unsupported
at new Hash (node:internal/crypto/hash:69:19)
at Object.createHash (node:crypto:133:10)
at filename (/app/node_modules/babel-loader/lib/fs-cache.js:76:21)
at /app/node_modules/babel-loader/lib/fs-cache.js:107:37
at /app/node_modules/mkdirp/index.js:48:26
at FSReqCallback.oncomplete (node:fs:203:5) {
opensslErrorStack: [ ‘error:03000086:digital envelope routines::initialization error’ ],
library: ‘digital envelope routines’,
reason: ‘unsupported’,
code: ‘ERR_OSSL_EVP_UNSUPPORTED’
}

Node.js v18.19.0

So my problem comes down to this:
Although I want to load nodejs12 and my docker container throws the typical script deprecation warning” because of ancient nodejs12, after the installation routine, there’s node.js v18 and npm v9 running inside, which crashes afterwards with my package-lock.json (created with another npm version).

In ran apt-get remove -y nodejs inside 210_extensions_node.sh before (re-)installing nodejs12. It has no effect.

I also ran npm --version outside docker in my terminal:

npm version
{
npm: '9.6.7',
node: '18.17.0',
acorn: '8.8.2',
ada: '2.5.0',
ares: '1.19.1',
brotli: '1.0.9',
cldr: '43.0',
icu: '73.1',
llhttp: '6.0.11',
modules: '108',
napi: '9',
nghttp2: '1.52.0',
nghttp3: '0.7.0',
ngtcp2: '0.8.1',
openssl: '3.0.9+quic',
simdutf: '3.2.12',
tz: '2023c',
undici: '5.22.1',
unicode: '15.0',
uv: '1.44.2',
uvwasi: '0.0.18',
v8: '10.2.154.26-node.26',
zlib: '1.2.13.1-motley'
}

It’s nearly the same version as inside the docker container. It’s just a guess, but maybe, something from outside suddenly seems to affect the nodjs-version inside the docker container. I did not experience this behavior before.

I already searched stack overflow and just got this equivalent: Docker: npm not found But I already tried to implement the suggested solutions (e.g. installing curl, removing nodes before reinstalling, specify version via apt-get install -y nodejs=12.*-1nodesource1 (throws even a “node: command not found” and “npm:command not found”-error)without effect, so maybe my problem differs.

So:

  1. Why does docker load nodejs18 instead of nodejs12?
  2. Any ideas how to force docker to use nodejs12?
  3. Any ideas why npm-command is not available inside docker anymore without explicitly installing it, although it should come with nodes-installation out of the box?
  4. Any ideas how to fix this?

Thank you very much!

New contributor

Mirko H. is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật