skip to Main Content

I am using the following docker file have both python3 and node 14 in my docker image.

FROM python:3.8-slim

ENV PYTHONDONTWRITEBYTECODE 1
ENV PYTHONUNBUFFERED 1
ENV DJANGO_DEVELOPMENT 1

#Installing neccessary packages
RUN apt-get update && apt-get install -y git curl virtualenv default-mysql-server default-mysql-client
RUN curl -sL https://deb.nodesource.com/setup_14.x | bash -
RUN apt-get install nodejs -y
RUN npm install -g @vue/cli

#Installing Python dependencies
RUN pip install --upgrade pip && pip install nodeenv

As you see I am installing node via curl -sL https://deb.nodesource.com/setup_14.x | bash - and apt-get install nodejs -y which should install both npm and nodejs. The problem is that the image is returning an error because it does not find npm, I get this error when I run docker build .

 => [internal] load build definition from dev.Dockerfile                                                                                                           0.1s 
 => => transferring dockerfile: 482B                                                                                                                               0.0s 
 => [internal] load .dockerignore                                                                                                                                  0.0s 
 => => transferring context: 2B                                                                                                                                    0.0s
 => [internal] load metadata for docker.io/library/python:3.8-slim                                                                                                 0.4s
 => [1/6] FROM docker.io/library/python:3.8-slim@sha256:10e07e36f86af4371accc42642852aa60eab74e6896fc065345ebc2c576eec0d                                           0.0s
 => CACHED [2/6] RUN apt-get update && apt-get install -y git curl virtualenv default-mysql-server default-mysql-client                                            0.0s
 => CACHED [3/6] RUN curl -sL https://deb.nodesource.com/setup_14.x | bash -                                                                                       0.0s
 => CACHED [4/6] RUN apt-get install nodejs -y                                                                                                                     0.0s
 => ERROR [5/6] RUN npm install -g @vue/cli                                                                                                                        0.3s
------                                                                                                                                                                  
 > [5/6] RUN npm install -g @vue/cli:
#0 0.267 /bin/sh: 1: npm: not found
------
dev.Dockerfile:11
--------------------
   9 |     RUN curl -sL https://deb.nodesource.com/setup_14.x | bash -
  10 |     RUN apt-get install nodejs -y
  11 | >>> RUN npm install -g @vue/cli
  12 |     
  13 |     #Installing Python dependencies
--------------------
ERROR: failed to solve: process "/bin/sh -c npm install -g @vue/cli" did not complete successfully: exit code: 127

for completeness this is my package.json

{
  "name": "name",
  "version": "0.1.0",
  "private": true,
  "resolutions": {
    "glob-parent": "^5.1.2",
    "node-forge": "1.3.0",
    "ansi-regex": "5.0.1",
    "ejs": "3.1.7"
  },
  "scripts": {
    "preinstall": "npx npm-force-resolutions",
    "serve": "vue-cli-service serve",
    "build": "vue-cli-service build",
    "test:unit": "vue-cli-service test:unit --setupTestFrameworkScriptFile=./tests/setup.js",
    "lint": "vue-cli-service lint"
  },
  "dependencies": {
    "axios": "^0.24.0",
    "core-js": "^3.22.7",
    "js-cookie": "^3.0.1",
    "vue": "^2.6.11",
    "vue-pdf-app": "^2.1.0",
    "vue-router": "^3.5.4",
    "vue-spinner": "^1.0.4",
    "vuetify": "^2.6.6"
  },
  "devDependencies": {
    "@vue/cli-plugin-babel": "~4.5.0",
    "@vue/cli-plugin-eslint": "~4.5.0",
    "@vue/cli-plugin-router": "~4.5.0",
    "@vue/cli-plugin-unit-jest": "~4.5.0",
    "@vue/cli-service": "~4.5.0",
    "@vue/eslint-config-airbnb": "^5.0.2",
    "@vue/test-utils": "^1.0.3",
    "babel-eslint": "^10.1.0",
    "eslint": "^6.7.2",
    "eslint-plugin-import": "^2.26.0",
    "eslint-plugin-vue": "^6.2.2",
    "sass": "~1.32.0",
    "sass-loader": "^10.2.1",
    "vue-cli-plugin-vuetify": "^2.4.8",
    "vue-template-compiler": "^2.6.11",
    "vuetify-loader": "^1.7.0"
  },
  "eslintConfig": {
    "rules": {
      "no-console": "off"
    }
  }
}

I do not know what to do. I have tried to add RUN apt-get install npm but but installs a wrong version of npm that then breaks the code.

2

Answers


  1. Chosen as BEST ANSWER

    As a partial solution I needed to use n

    I added the lines

     RUN apt-get install -y npm
     RUN npm install -g n
     RUN n 14
     RUN npm install -g @vue/cli
    

    doing this I force npm to use the version 14, which fixes the error that I was getting before only installing npm.

    the complete dockerfile is this:

    FROM python:3.8-slim
    
    ENV PYTHONDONTWRITEBYTECODE 1
    ENV PYTHONUNBUFFERED 1
    ENV DJANGO_DEVELOPMENT 1
    
    #Installing neccessary packages
    RUN apt-get update && apt-get install -y git curl virtualenv default-mysql-server default-mysql-client
    
    RUN curl -sL https://deb.nodesource.com/setup_14.x | bash -
    RUN apt-get install -y nodejs
    RUN apt-get install -y npm
    RUN npm install -g n
    RUN n 14
    RUN npm install -g @vue/cli
    
    #Installing Python dependencies
    RUN pip install --upgrade pip && pip install nodeenv
    

    This works but it seems to me like a very bad solution. Does anyone understand why I need to do this?


  2. In the npm docs, they recommend installing with nvm.

    Also, it is stated there:

    Note: to download the latest version of npm, on the command line, run the
    following command:

    npm install -g npm

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search