3

I need to have access to both npm and pipenv in the same container. I'm thinking the best way to accomplish this is with a multistage build.

If I do something like this:

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

FROM node:8
npm install

How do I make sure that the pipenv binary is not discarded? What files do I need to copy from the previous stage so that pipenv is available in the final image?

dopatraman
  • 13,416
  • 29
  • 90
  • 154
  • no need multi-stage build, start from base image `python:3.7` and install node in it , will be the straightforward solution – BMW Jan 18 '19 at 01:38
  • how do i install node? i'd rather not do this: https://github.com/nodejs/docker-node/blob/master/11/alpine/Dockerfile, way too many layers @BMW – dopatraman Jan 18 '19 at 01:38
  • image 'python:3.7` is `Debian GNU/Linux`. so read this: https://nodejs.org/en/download/package-manager/#debian-and-ubuntu-based-linux-distributions-enterprise-linux-fedora-and-snap-packages – BMW Jan 18 '19 at 01:41
  • @BMW how do you know that python:3.7 is debian? the dockerfile says it is "stretch" (https://github.com/docker-library/python/blob/ab8b829cfefdb460ebc17e570332f0479039e918/3.7/stretch/Dockerfile) – dopatraman Jan 18 '19 at 01:46

1 Answers1

7

multi-stage build is not required in your case. Start from base image python:3.7 and install node in it , will be the straightforward solution

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

how do you know the image python:3.7 is 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:/#

Reference:

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 Installation instructions

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
BMW
  • 42,880
  • 12
  • 99
  • 116