代码之家  ›  专栏  ›  技术社区  ›  dopatraman

同一容器中的python和nodejs的多级构建

  •  0
  • dopatraman  · 技术社区  · 6 年前

    我需要两者都能接触到 npm pipenv 在同一个容器中。我认为实现这一目标的最佳方法是采用多级构建。

    如果我这样做:

    FROM python:3.7
    COPY Pipfile /app/Pipfile
    RUN pip install pipenv
    
    FROM node:8
    npm install
    

    我如何确保 皮彭夫 二进制文件没有被丢弃?我需要从上一阶段复制哪些文件,以便pipenv在最终图像中可用?

    1 回复  |  直到 6 年前
        1
  •  0
  •   BMW    6 年前

    在您的案例中,不需要多阶段构建。从基础图像开始 python:3.7 并在其中安装节点,将是一个简单的解决方案

    FROM python:3.7
    COPY Pipfile /app/Pipfile
    RUN pip install pipenv
    
    # Using Debian, as root
    RUN curl -sL https://deb.nodesource.com/setup_11.x | bash -
    RUN apt-get install -y nodejs
    

    你怎么知道python:3.7是debian?

    $ docker run -ti --rm python:3.7 bash
    root@eb654212ef67:/# cat /etc/*release
    PRETTY_NAME="Debian GNU/Linux 9 (stretch)"
    NAME="Debian GNU/Linux"
    VERSION_ID="9"
    VERSION="9 (stretch)"
    ID=debian
    HOME_URL="https://www.debian.org/"
    SUPPORT_URL="https://www.debian.org/support"
    BUG_REPORT_URL="https://bugs.debian.org/"
    root@eb654212ef67:/#
    

    参考文献:

    https://nodejs.org/en/download/package-manager/#debian-and-ubuntu-based-linux-distributions-enterprise-linux-fedora-and-snap-packages

    https://github.com/nodesource/distributions/blob/master/README.md

    节点安装说明

    Node.js v11.x:
    
    # Using Ubuntu
    curl -sL https://deb.nodesource.com/setup_11.x | sudo -E bash -
    sudo apt-get install -y nodejs
    
    # Using Debian, as root
    curl -sL https://deb.nodesource.com/setup_11.x | bash -
    apt-get install -y nodejs
    Node.js v10.x:
    
    # Using Ubuntu
    curl -sL https://deb.nodesource.com/setup_10.x | sudo -E bash -
    sudo apt-get install -y nodejs
    
    # Using Debian, as root
    curl -sL https://deb.nodesource.com/setup_10.x | bash -
    apt-get install -y nodejs
    Node.js v8.x:
    
    # Using Ubuntu
    curl -sL https://deb.nodesource.com/setup_8.x | sudo -E bash -
    sudo apt-get install -y nodejs
    
    # Using Debian, as root
    curl -sL https://deb.nodesource.com/setup_8.x | bash -
    apt-get install -y nodejs
    
    推荐文章