Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Multistage build for python and nodejs in the same container

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?

like image 300
dopatraman Avatar asked Sep 12 '26 08:09

dopatraman


1 Answers

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
like image 99
BMW Avatar answered Sep 15 '26 01:09

BMW



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!