skip to Main Content

I have a problem. I want to install Python and Node.js in a same image. But there is a problem in copying the package.json. The error says no such file or directory, open '/opt/app/src/package.json'. So what is the probleme here? What did I might wrong?

I looked at Docker-compose up : no such file or directory, open '/usr/src/app/package.json' , but I don’t know where my error is.

Dockerfile

FROM python:3.7-slim AS build
RUN mkdir -p /opt/app/src
COPY ./requirements.txt /opt/app/src
RUN pip install -r /opt/app/src/requirements.txt

FROM node:14-slim
RUN mkdir -p /opt/app/src
WORKDIR /opt/app/src
COPY --from=build package-*.json ./
RUN npm install
EXPOSE 4001
CMD npm start

Structure

|-- app.js
|-- requriments.txt
|-- test.js
|-- package.json
|-- routes
|-- |-- model.py
|-- |-- post_price.js

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

Error


CONTAINERS





Attaching to backend_airbnb

backend_airbnb | npm ERR! code ENOENT

backend_airbnb | npm ERR! syscall open

backend_airbnb | npm ERR! path /opt/app/src/package.json

backend_airbnb | npm ERR! errno -2

backend_airbnb | npm ERR! enoent ENOENT: no such file or directory, open '/opt/app/src/package.json'

backend_airbnb | npm ERR! enoent This is related to npm not being able to find a file.

backend_airbnb | npm ERR! enoent 

backend_airbnb | 

backend_airbnb | npm ERR! A complete log of this run can be found in:

backend_airbnb | npm ERR!     /root/.npm/_logs/2022-02-21T08_33_58_188Z-debug.log

backend_airbnb exited with code 254

2

Answers


  1. It’s probably because of the COPY.
    Try this: COPY --from=build package*.json ./.

    Difference package*.json vs package-*.json

    This will match "package.json" and "package-lock.json" – previously only the latter did and the package.json didn’t copy (which is required to install deps).

    Login or Signup to reply.
  2. You can probably install python in your nodejs image. This is a very basic demostration of what you can do.

    FROM node:14-alpine
    WORKDIR /app
    
    # Install Python
    RUN apk add --no-cache python3 py3-pip
    
    # Copy all required files    
    COPY . .
    
    # Install your python packages
    RUN pip install -r /app/requirements.txt
    
    # Install node applications
    RUN npm install
    
    # Expose Port
    EXPOSE 4001
    
    # Start App
    CMD npm start
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search