I have written a small script in Node.js that calls a Python file and intercepts the output of the Python file. I first build the Dockerfile with docker build -t backend_airbnb .
then I run the docker compose with docker compose up -d
. After that I check if the container is running, but it closes directly without an error message. It only says backend_airbnb exited with code 0
.
How can I build a multistage Dockerfile that first installs the python requirements and then installs Node (or vice versa) and runs npm start
? So that I can execute my Python file when a POST request goes in.
folder structure
|-- app.js
|-- requriments.txt
|-- test.js
|-- routes
|-- |-- model.py
|-- |-- post_price.js
Dockerfile
FROM python:3.6.8
#RUN mkdir -p /usr/src/app
COPY requirements.txt /opt/app/requirements.txt
WORKDIR /opt/app
RUN pip install -r requirements.txt
FROM node:14
WORKDIR /opt/app
COPY package*.json ./
RUN npm install
ENV NODE_ENV=container
COPY . .
EXPOSE 4001
CMD npm start
docker-compose.yml
version: '3.8'
services:
backend:
container_name: backend_airbnb
image: backend_airbnb
expose:
- "4001"
ports:
- "4001:4001"
networks:
- backendProxyNetwork
networks:
backendProxyNetwork:
external: true
EDIT Did not work, still the same problem New Dockerfile (Multiple FROMs - what it means)
FROM python:3.6.8 AS build
#RUN mkdir -p /usr/src/app
COPY requirements.txt /opt/app/requirements.txt
WORKDIR /opt/app
RUN pip install -r requirements.txt
FROM node:14
WORKDIR /opt/app
COPY --from=build package*.json ./
RUN npm install
ENV NODE_ENV=container
COPY . .
EXPOSE 4001
CMD npm start