Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Docker node:8.16.0-alpine Error: not found: python2

I need run npm rebuild node-sass --force inside my docker container

But i got an error (even after i install python already)

Error: Can't find Python executable "python", you can set the PYTHON env variable.

This is my Dockerfile

FROM node:8.16.0-alpine

RUN mkdir /app
WORKDIR /app

# --no-cache: download package index on-the-fly, no need to cleanup afterwards
# --virtual: bundle packages, remove whole bundle at once, when done
RUN apk --no-cache --virtual build-dependencies add \
    python \
    make \
    g++ \
    bash \
    && npm install \
    && apk del build-dependencies

RUN npm install -g nodemon

COPY package.json package.json
COPY client/package.json client/package.json

RUN npm install
RUN npm run install:client
RUN npm uninstall node-sass && npm install node-sass
RUN npm rebuild node-sass --force

COPY . .

LABEL maintainer="Varis Darasirikul"

VOLUME ["/app/public"]

CMD npm run dev

This my docker-compose

version: '3'

services:
  web:
      build: '.'
      container_name: node-web
      # env_file:
        # - '.env'
      ports:
        - '80:8000'
        - '5000:5000'
        - '3000:3000'
      volumes:
        - '.:/app'
      networks:
        - front-tier
        - back-tier
      # depends_on:
        # - redis
        # - db

networks:
  front-tier:
  back-tier:

Even when i run

docker-compose up --build --force-recreate

Still not working

How to fix this?

Thanks!

like image 278
Varis Darasirikul Avatar asked Dec 22 '22 22:12

Varis Darasirikul


2 Answers

The problem is that Python is simply not installed.

Your parent image, node:8.16.0-alpine doesn't include Python. You can verify this:

> docker run -it node:8.16.0-alpine sh
/ # python
sh: python: not found

The misunderstanding might come from the fact that you are temporarily installing python on this line:

RUN apk --no-cache --virtual build-dependencies add \
    python \
    ...

It's added to the virtual package build-dependencies, but just after npm install completes, you run apk del build-dependencies which removes Python again!

Just move the line where you uninstall build-dependencies to after you have done all npm rebuild stuff and I think it will work.

like image 187
André Laszlo Avatar answered Dec 25 '22 13:12

André Laszlo


Because you are using alpine image which is a small image that doesn't include python. You can install python by running apk add and remove it after you have installed node modules.

FROM node:alpine

RUN apk add --no-cache --virtual .gyp \
        python \
        make \
        g++ \
    && npm install \
    && apk del .gyp

More read: https://github.com/nodejs/docker-node/issues/282

like image 40
Chhaileng Avatar answered Dec 25 '22 11:12

Chhaileng