docker - 在同一容器中为 python 和 nodejs 多阶段构建
问题描述
npm
我需要在同pipenv
一个容器中访问两者。我认为实现这一目标的最佳方法是使用多阶段构建。
如果我做这样的事情:
FROM python:3.7
COPY Pipfile /app/Pipfile
RUN pip install pipenv
FROM node:8
npm install
如何确保pipenv
二进制文件不被丢弃?我需要从上一阶段复制哪些文件才能使 pipenv 在最终图像中可用?
解决方案
您的情况不需要多阶段构建。从基础镜像开始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://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
推荐阅读
- android - 从其他适配器更新 recyclerview 适配器
- typescript - 我收到错误,polyfills-es2015.js:4001 未处理的承诺拒绝:指定音频 id 的引用不存在。; 区:
; 任务 - php - Laravel 解决 Storage::append() 中“允许的内存大小为 134217728 字节已耗尽”错误的解决方案
- c - 如果使用这个程序,为什么第一个字母不进入数组?
- .net - PowerShell 工作流在通过任务计划程序中的计划作业运行时自行挂起
- javascript - 自定义视频插件在 IE 浏览器中不起作用
- python - 使用此代码时得到一个空列表,您能解释一下原因吗?
- reactjs - 如何为此组件设置添加购物车操作?
- c# - 检测一个点是否没有被其他点包围
- typescript - Typescript inlines .d.ts 编译后导入