close

How to install Python on nodejs Docker image

Hello Guys, How are you all? Hope You all Are Fine. Today We Are Going To learn about How to install Python on nodejs Docker image in Python. So Here I am Explain to you all the possible Methods here.

Without wasting your time, Let’s start This Article.

Table of Contents

How to install Python on nodejs Docker image?

  1. How to install Python on nodejs Docker image?

    In fact, this is not a docker question, just a debian question. You need always do apt-get update before install package. So, for you scenario, it should be:

  2. install Python on nodejs Docker image

    In fact, this is not a docker question, just a debian question. You need always do apt-get update before install package. So, for you scenario, it should be:

Method 1

In fact, this is not a docker question, just a debian question. You need always do apt-get update before install package. So, for you scenario, it should be:

RUN apt-get update || : && apt-get install python -y

As per your comments:

W: Failed to fetch Unable to find expected entry ‘main/binary-amd64/Packages’ in Release file (Wrong sources.list entry or malformed file) E: Some index files failed to download. They have been ignored, or old ones used instead. The command ‘/bin/sh -c apt-get update && apt-get install python -y’ returned a non-zero code: 100

So, you can add || : after apt-get to ignore the error, as at that time python meta data already finished downloading with other previous url hit, so you can bypass the error.

Update:

A whole workable solution in case you need to compare:

a.py:

print("success")

index.js:

const spawn = require("child_process").spawn;
console.log('PATH:::::');

console.log(process.env.PATH);
const pythonProcess = spawn('python', ['/app/a.py']);
pythonProcess.stdout.on('data', (data) => {
    console.log('DATA::::');
    console.log(data.toString());
});

pythonProcess.stderr.on('data', (data) => {
    console.log("wow");
    console.log(data.toString());
});

Dockerfile:

FROM node:9-slim

RUN apt-get update || : && apt-get install python -y

WORKDIR /app
COPY . /app
CMD ["node", "index.js"]

Try command:

[email protected]:~/gg$ docker build -t abc:1 .
Sending build context to Docker daemon  4.096kB
...
Successfully built 756b13952760
Successfully tagged abc:1

[email protected]:~/gg$ docker run abc:1
PATH:::::
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
DATA::::
success

Summery

It’s all About this issue. Hope all Methods helped you a lot. Comment below Your thoughts and your queries. Also, Comment below which Method worked for you? Thank You.

Also, Read