2

npm我需要在同pipenv一个容器中访问两者。我认为实现这一目标的最佳方法是使用多阶段构建。

如果我做这样的事情:

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

FROM node:8
npm install

如何确保pipenv二进制文件不被丢弃?我需要从上一阶段复制哪些文件才能使 pipenv 在最终图像中可用?

4

1 回答 1

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
于 2019-01-18T01:46:03.970 回答