代码之家  ›  专栏  ›  技术社区  ›  Varis Darasirikul

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

  •  0
  • Varis Darasirikul  · 技术社区  · 5 年前

    我需要跑步 npm rebuild node-sass --force 在我的docker容器里

    但我犯了一个错误(即使我已经安装了python)

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

    这是我的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
    

    这是我的码头工人写的

    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:
    

    即使我跑的时候

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

    还是不行

    如何解决这个问题?

    谢谢

    0 回复  |  直到 5 年前
        1
  •  7
  •   André Laszlo    5 年前

    问题是Python根本没有安装。

    你的父母形象, node:8.16.0-alpine 不包括Python。您可以验证这一点:

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

    误解可能是因为您正在这一行临时安装python:

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

    它被添加到虚拟包中 build-dependencies 但就在那之后 npm install 完成后,您可以运行 apk del build-dependencies 这又删除了Python!

    只需将线路移到卸载位置即可 构建依赖项 在你做完所有的事之后 npm rebuild 我想这会管用的。

        2
  •  4
  •   Chhaileng    4 年前

    因为你正在使用 alpine 图像是一个小图像,不包括 python .你可以安装 python 通过跑步 apk add 并在安装节点模块后将其卸下。

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

    更多阅读: https://github.com/nodejs/docker-node/issues/282

        3
  •  0
  •   Shariati    4 年前

    另一种解决方案是使用 bcryptjs .性能可能不会有多大影响,但是使用工作代替应用解决方案!