Docker 节点:8.16.0-alpine 错误:未找到:python2

Var*_*kul 4 python node.js docker alpine-linux

我需要npm rebuild node-sass --force在我的 docker 容器内运行

但是我遇到了一个错误(即使在我已经安装了 python 之后)

Error: Can't find Python executable "python", you can set the PYTHON env variable.
Run Code Online (Sandbox Code Playgroud)

这是我的 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
Run Code Online (Sandbox Code Playgroud)

这是我的 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:
Run Code Online (Sandbox Code Playgroud)

即使我跑

docker-compose up --build --force-recreate
Run Code Online (Sandbox Code Playgroud)

还是行不通

如何解决这个问题?

谢谢!

And*_*zlo 6

问题是根本没有安装 Python。

您的父映像node:8.16.0-alpine不包含 Python。您可以验证这一点:

> docker run -it node:8.16.0-alpine sh
/ # python
sh: python: not found
Run Code Online (Sandbox Code Playgroud)

误会可能是因为你暂时在这一行安装了python:

RUN apk --no-cache --virtual build-dependencies add \
    python \
    ...
Run Code Online (Sandbox Code Playgroud)

它已添加到虚拟包中build-dependencies,但在npm install完成后,您apk del build-dependencies再次运行它删除了 Python!

build-dependencies完成所有npm rebuild工作后,只需将卸载的行移到哪里,我认为它会起作用。